Review feedback.

pull/3950/head
Tom Wilkie 2018-03-12 14:27:48 +00:00
parent 97a5fc8cbb
commit fdb574b608
1 changed files with 6 additions and 9 deletions

View File

@ -430,14 +430,15 @@ func (s *shards) runShard(i int) {
pendingSamples := model.Samples{} pendingSamples := model.Samples{}
timer := time.NewTimer(s.qm.cfg.BatchSendDeadline) timer := time.NewTimer(s.qm.cfg.BatchSendDeadline)
defer func() { stop := func() {
if !timer.Stop() { if !timer.Stop() {
select { select {
case <-timer.C: case <-timer.C:
default: default:
} }
} }
}() }
defer stop()
for { for {
select { select {
@ -454,16 +455,11 @@ func (s *shards) runShard(i int) {
queueLength.WithLabelValues(s.qm.queueName).Dec() queueLength.WithLabelValues(s.qm.queueName).Dec()
pendingSamples = append(pendingSamples, sample) pendingSamples = append(pendingSamples, sample)
for len(pendingSamples) >= s.qm.cfg.MaxSamplesPerSend { if len(pendingSamples) >= s.qm.cfg.MaxSamplesPerSend {
s.sendSamples(pendingSamples[:s.qm.cfg.MaxSamplesPerSend]) s.sendSamples(pendingSamples[:s.qm.cfg.MaxSamplesPerSend])
pendingSamples = pendingSamples[s.qm.cfg.MaxSamplesPerSend:] pendingSamples = pendingSamples[s.qm.cfg.MaxSamplesPerSend:]
if !timer.Stop() { stop()
select {
case <-timer.C:
default:
}
}
timer.Reset(s.qm.cfg.BatchSendDeadline) timer.Reset(s.qm.cfg.BatchSendDeadline)
} }
@ -472,6 +468,7 @@ func (s *shards) runShard(i int) {
s.sendSamples(pendingSamples) s.sendSamples(pendingSamples)
pendingSamples = pendingSamples[:0] pendingSamples = pendingSamples[:0]
} }
timer.Reset(s.qm.cfg.BatchSendDeadline)
} }
} }
} }