Commit 5912f5bd authored by ldeffenb's avatar ldeffenb Committed by GitHub

feat: flush metrics in separate goroutine (#2424)

parent 87d83ed7
...@@ -506,18 +506,33 @@ func (k *Kad) manage() { ...@@ -506,18 +506,33 @@ func (k *Kad) manage() {
peerConnChan2 := make(chan *peerConnInfo) peerConnChan2 := make(chan *peerConnInfo)
go k.connectionAttemptsHandler(ctx, &wg, peerConnChan, peerConnChan2) go k.connectionAttemptsHandler(ctx, &wg, peerConnChan, peerConnChan2)
k.wg.Add(1)
go func() {
defer k.wg.Done()
for { for {
select { select {
case <-k.halt:
return
case <-k.quit: case <-k.quit:
return return
case <-time.After(15 * time.Second): case <-time.After(5 * time.Minute):
start := time.Now() start := time.Now()
if err := k.collector.Flush(); err != nil { if err := k.collector.Flush(); err != nil {
k.metrics.InternalMetricsFlushTotalErrors.Inc() k.metrics.InternalMetricsFlushTotalErrors.Inc()
k.logger.Debugf("kademlia: unable to flush metrics counters to the persistent store: %v", err) k.logger.Debugf("kademlia: took %s unable to flush metrics counters to the persistent store: %v", time.Since(start), err)
} else { } else {
k.metrics.InternalMetricsFlushTime.Observe(float64(time.Since(start).Nanoseconds())) k.metrics.InternalMetricsFlushTime.Observe(float64(time.Since(start).Nanoseconds()))
k.logger.Tracef("kademlia took %s to flush", time.Since(start))
}
}
} }
}()
for {
select {
case <-k.quit:
return
case <-time.After(15 * time.Second):
k.notifyManageLoop() k.notifyManageLoop()
case <-k.manageC: case <-k.manageC:
start := time.Now() start := time.Now()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment