Allow to obtain memory metrics by PID
What does this MR do and why?
This change supports upcoming changes for #370079 (closed).
In that issue I am looking to extend our memory-watchdog
, a background task responsible for monitoring Puma workers, to also stop workers based on private memory expansion (currently it is based only on heap fragmentation).
For that to work, we want to compare worker memory with master memory to measure the degree of private memory expansion. This requires reading the parent process' procfs
files, which so far we only did for the current process (the caller).
This is currently unused and safe to deploy since we call it without arguments everywhere, in which case it collapses to the previous semantics of probing self
.
How to set up and validate locally
Verify the default behavior is still in place:
- Run
rails console
- Call
Gitlab::Metrics::System.memory_usage_rss
. It should return RSS in bytes for the console process. - Call
Gitlab::Metrics::System.memory_usage_rss(pid: <pid>)
. It should return RSS in bytes for that process instead.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #370079 (closed)