metrics icon indicating copy to clipboard operation
metrics copied to clipboard

Sampling support

Open hagen1778 opened this issue 4 years ago • 1 comments

Metrics update in application's hot path may be expensive. Some heavy-loaded web servers or processing pipelines usually serve hundreds of thousands of events per second, and to have the visibility they also increment a bunch of metrics for each event. It would be cool, if metrics package could have native sampling support. For example:

requestsTotal = metrics.NewCounterSampled("requests_total", 0.1)

Every call to requestsTotal.Inc() will have 10% chance to actually increment the counter, and 90% chance to do nothing. But when increment actually happens, it will be +=10 instead of +=1.

Workaround. Batch metrics updates in a hot path and make them periodic (e.g. every 100ms) with a fixed rate.

hagen1778 avatar May 12 '21 08:05 hagen1778

It would be great to have performance numbers and/or cpu profiles obtained from highly loaded systems where metrics sampling could result in better performance.

valyala avatar May 17 '21 23:05 valyala