Use fixed value for the batch timer

This commit is contained in:
Julian Kornberger 2017-01-30 00:44:56 +01:00
parent 54cdd39eb8
commit fd6a169b18
2 changed files with 4 additions and 5 deletions

View File

@ -17,6 +17,7 @@ const (
MeasurementFirmware = "firmware" // Measurement for firmware statistics
MeasurementModel = "model" // Measurement for model statistics
batchMaxSize = 500
batchTimeout = 5 * time.Second
)
type DB struct {
@ -121,8 +122,7 @@ func (db *DB) addWorker() {
var bp client.BatchPoints
var err error
var writeNow, closed bool
batchDuration := db.config.Influxdb.SaveInterval.Duration
timer := time.NewTimer(batchDuration)
timer := time.NewTimer(batchTimeout)
for !closed {
// wait for new points
@ -131,7 +131,7 @@ func (db *DB) addWorker() {
if ok {
if bp == nil {
// create new batch
timer.Reset(batchDuration)
timer.Reset(batchTimeout)
if bp, err = client.NewBatchPoints(bpConfig); err != nil {
log.Fatal(err)
}
@ -142,7 +142,7 @@ func (db *DB) addWorker() {
}
case <-timer.C:
if bp == nil {
timer.Reset(batchDuration)
timer.Reset(batchTimeout)
} else {
writeNow = true
}

View File

@ -34,7 +34,6 @@ type Config struct {
Database string
Username string
Password string
SaveInterval Duration // Save nodes every n seconds
DeleteInterval Duration // Delete stats of nodes every n minutes
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
}