You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow customizing the suffix function in multiprocess mode (instead of os.getpid()) #509
One frequent issue with using prometheus_client in multiprocess mode is that you can end up with a lot of files which can severely impact the collecting performance ending with scraping timeouts in the worth cases.
This comes from the fact that to prevent concurrent usage, prometheus_client uses os.getpid() to name its metrics file and ensure that each process only touches its own files: it's a perfectly good and simple design.
However for long running processes spawning new processes every few minutes you can end up with several thousands files after a few months.
But in some cases, you have access to other methods to ensure that each process is uniquely identified (and ensure that each process only touches uniquely identified metrics files).
Would it be possible to allow customizing (& document as public API) the function generating metrics file suffix ?
(Of course, this would still be an use-at-your-own-risk escape hatch).
For instance, using uWSGI, we might want to use uwsgi.worker_id():
from prometheus_client import values
import uwsgi
values.ValueClass = values.MultiProcessValue(uwsgi.worker_id)
Or when each worker has its own task and you can ensure that only one worker at a time is dealing with this task (thanks to a postgres advisory lock in my case).
The problem is that that isn't safe if the process then later forks, it took a while to get the current logic right and I'm not sure how correctly it'll work with anything that's not actually a pid.
The problem is that that isn't safe if the process then later forks, it took a while to get the current logic right and I'm not sure how correctly it'll work with anything that's not actually a pid.
Yes, hence the "use-at-your-own-risk escape hatch".
This would be clearly documented as a "I know what I'm doing" hook but I think that in most cases the user has a fairly good understanding whether its code will spawn a subprocess or not (typically web server workers don't).
I don't think this is something that should go in the readme, we already have issues with users failing to follow the docs that are there and this would be handing them a chainsaw to juggle. I am open to code changes that'd make this easier to do for those who know what they're up to though.
Activity
brian-brazil commentedon Feb 10, 2020
The problem is that that isn't safe if the process then later forks, it took a while to get the current logic right and I'm not sure how correctly it'll work with anything that's not actually a pid.
xavfernandez commentedon Feb 10, 2020
Yes, hence the "use-at-your-own-risk escape hatch".
This would be clearly documented as a "I know what I'm doing" hook but I think that in most cases the user has a fairly good understanding whether its code will spawn a subprocess or not (typically web server workers don't).
brian-brazil commentedon Feb 11, 2020
I don't think this is something that should go in the readme, we already have issues with users failing to follow the docs that are there and this would be handing them a chainsaw to juggle. I am open to code changes that'd make this easier to do for those who know what they're up to though.
brian-brazil commentedon Jan 26, 2021
I believe this can be closed now.