Review feedback.

This commit is contained in:
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{}
timer := time.NewTimer(s.qm.cfg.BatchSendDeadline)
defer func() {
stop := func() {
if !timer.Stop() {
select {
case <-timer.C:
default:
}
}
}()
}
defer stop()
for {
select {
@ -454,16 +455,11 @@ func (s *shards) runShard(i int) {
queueLength.WithLabelValues(s.qm.queueName).Dec()
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])
pendingSamples = pendingSamples[s.qm.cfg.MaxSamplesPerSend:]
if !timer.Stop() {
select {
case <-timer.C:
default:
}
}
stop()
timer.Reset(s.qm.cfg.BatchSendDeadline)
}
@ -472,6 +468,7 @@ func (s *shards) runShard(i int) {
s.sendSamples(pendingSamples)
pendingSamples = pendingSamples[:0]
}
timer.Reset(s.qm.cfg.BatchSendDeadline)
}
}
}