mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
Re-use timer instead of creating new ones on every sample
The docs for `time.After()` note that "The underlying Timer is not recovered by the garbage collector until the timer fires".
This commit is contained in:
parent
f64014f70b
commit
8a4535e6ad
|
@ -430,6 +430,8 @@ func (s *shards) runShard(i int) {
|
||||||
// anyways.
|
// anyways.
|
||||||
pendingSamples := model.Samples{}
|
pendingSamples := model.Samples{}
|
||||||
|
|
||||||
|
timer := time.NewTimer(s.qm.cfg.BatchSendDeadline)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case sample, ok := <-queue:
|
case sample, ok := <-queue:
|
||||||
|
@ -449,7 +451,11 @@ func (s *shards) runShard(i int) {
|
||||||
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:]
|
||||||
}
|
}
|
||||||
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 {
|
if len(pendingSamples) > 0 {
|
||||||
s.sendSamples(pendingSamples)
|
s.sendSamples(pendingSamples)
|
||||||
pendingSamples = pendingSamples[:0]
|
pendingSamples = pendingSamples[:0]
|
||||||
|
|
Loading…
Reference in a new issue