func exec(conn *client.Client, query string) error { resp, err := conn.Query(client.Query{ Command: query, }) if err != nil { return err } if resp.Err != nil { return resp.Err } return nil }
func writePoints(num int, gorutineClient *client.Client, conf *Config, wg *sync.WaitGroup) { defer wg.Done() limit := 0 // batchCount := 1000 / conf.BatchCountPerSecond // writeTimeDuration := (time.Duration(batchCount)) * time.Millisecond // writeTimer := time.NewTimer(writeTimeDuration) batchSize := conf.BatchSize batchPointsInSameSeries := conf.BatchPointsInSameSeries tagKeySet := conf.TagKeySet fieldKeySet := conf.FieldKeySet r := rand.New(rand.NewSource(time.Now().UnixNano())) for { // <-writeTimer.C pts := make([]client.Point, batchSize) for i := 0; i < batchSize; i++ { tagSet := make(map[string]string, len(tagKeySet)) // tagSet := make(map[string]string, len(tagKeySet)+1) fieldSet := make(map[string]interface{}, len(fieldKeySet)) for _, tag := range tagKeySet { tagSet[tag] = tag + "_" + strconv.Itoa(num) } if !batchPointsInSameSeries { for _, tag := range tagKeySet { tagSet[tag] = tag + strconv.Itoa(i) } } for index, val := range fieldKeySet { valueContent := conf.FieldValueRange[index] if valueContent.Type == "float" { start, _ := strconv.ParseFloat(conf.FieldValueRange[index].Start, 32) end, _ := strconv.ParseFloat(conf.FieldValueRange[index].End, 32) v := start + r.Float64()*(end-start) fieldSet[val] = v } if conf.FieldValueRange[index].Type == "integer" { start, _ := strconv.Atoi(conf.FieldValueRange[index].Start) end, _ := strconv.Atoi(conf.FieldValueRange[index].End) v := start + r.Intn(end-start) fieldSet[val] = v } if conf.FieldValueRange[index].Type == "string" { } if conf.FieldValueRange[index].Type == "bool" { } } pts[i] = client.Point{ Measurement: conf.Measurement, Tags: tagSet, Fields: fieldSet, Time: time.Now(), Precision: conf.Precision, } } qlog.Info(pts[0].Time.UnixNano()) bp := client.BatchPoints{ Points: pts, Database: conf.Database, RetentionPolicy: conf.Retention, } qlog.Debugf("gorutine number is %d, Write %d points", num, len(bp.Points)) _, err := gorutineClient.Write(bp) if err != nil { qlog.Debug(err) return } limit++ if limit == conf.GorutineBatchLimit { qlog.Debugf("The %d has finished %d batches", num, limit) return } // writeTimer.Reset(writeTimeDuration) } }