metrics icon indicating copy to clipboard operation
metrics copied to clipboard

better performance for process_* metrics on linux

Open jelmd opened this issue 9 months ago • 1 comments

Current process_* metrics implementation for linux has a huge overhead by re-opening/closing files on each pull. Instead it should keep the process related files open (they do not change over lifetime) and let the OS auto-close them on exit. This way performance can be improved by factor 2..6.

Attaching 2 files as proof of concept/for comparison/micro benchmarking:

jelmd avatar Mar 20 '25 02:03 jelmd

The process_* metrics are usually read once per scrape interval. The usual scrape interval is in the range 10s - 30s. There is no practical sense in optimizing the code, which reads process_* metric values from various files at the operating system, since this won't reduce CPU usage of the process, which exposes these metrics, by any measurable value. On the other hand, this optimization may complicate further maintenance of the code and may lead to subtle bugs.

valyala avatar Aug 03 '25 19:08 valyala