Use fixed value for the batch timer
This commit is contained in:
parent
54cdd39eb8
commit
fd6a169b18
@ -17,6 +17,7 @@ const (
|
|||||||
MeasurementFirmware = "firmware" // Measurement for firmware statistics
|
MeasurementFirmware = "firmware" // Measurement for firmware statistics
|
||||||
MeasurementModel = "model" // Measurement for model statistics
|
MeasurementModel = "model" // Measurement for model statistics
|
||||||
batchMaxSize = 500
|
batchMaxSize = 500
|
||||||
|
batchTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
@ -121,8 +122,7 @@ func (db *DB) addWorker() {
|
|||||||
var bp client.BatchPoints
|
var bp client.BatchPoints
|
||||||
var err error
|
var err error
|
||||||
var writeNow, closed bool
|
var writeNow, closed bool
|
||||||
batchDuration := db.config.Influxdb.SaveInterval.Duration
|
timer := time.NewTimer(batchTimeout)
|
||||||
timer := time.NewTimer(batchDuration)
|
|
||||||
|
|
||||||
for !closed {
|
for !closed {
|
||||||
// wait for new points
|
// wait for new points
|
||||||
@ -131,7 +131,7 @@ func (db *DB) addWorker() {
|
|||||||
if ok {
|
if ok {
|
||||||
if bp == nil {
|
if bp == nil {
|
||||||
// create new batch
|
// create new batch
|
||||||
timer.Reset(batchDuration)
|
timer.Reset(batchTimeout)
|
||||||
if bp, err = client.NewBatchPoints(bpConfig); err != nil {
|
if bp, err = client.NewBatchPoints(bpConfig); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ func (db *DB) addWorker() {
|
|||||||
}
|
}
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
if bp == nil {
|
if bp == nil {
|
||||||
timer.Reset(batchDuration)
|
timer.Reset(batchTimeout)
|
||||||
} else {
|
} else {
|
||||||
writeNow = true
|
writeNow = true
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ type Config struct {
|
|||||||
Database string
|
Database string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
SaveInterval Duration // Save nodes every n seconds
|
|
||||||
DeleteInterval Duration // Delete stats of nodes every n minutes
|
DeleteInterval Duration // Delete stats of nodes every n minutes
|
||||||
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
|
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user