Browse Source

Merge pull request #3731 from bboreham/reuse-timer

Re-use timer in remote storage queue
pull/3798/merge
Tom Wilkie 7 years ago committed by GitHub
parent
commit
a730083cbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      storage/remote/queue_manager.go

8
storage/remote/queue_manager.go

@ -430,6 +430,8 @@ func (s *shards) runShard(i int) {
// anyways.
pendingSamples := model.Samples{}
timer := time.NewTimer(s.qm.cfg.BatchSendDeadline)
for {
select {
case sample, ok := <-queue:
@ -449,7 +451,11 @@ func (s *shards) runShard(i int) {
s.sendSamples(pendingSamples[:s.qm.cfg.MaxSamplesPerSend])
pendingSamples = pendingSamples[s.qm.cfg.MaxSamplesPerSend:]
}
case <-time.After(s.qm.cfg.BatchSendDeadline):
if !timer.Stop() {
<-timer.C
}
timer.Reset(s.qm.cfg.BatchSendDeadline)
case <-timer.C:
if len(pendingSamples) > 0 {
s.sendSamples(pendingSamples)
pendingSamples = pendingSamples[:0]

Loading…
Cancel
Save