[metricbeat][process/darwin] 1 MiB buffer allocated per process per collection cycle causes memory growth under low GOMAXPROCS
Open
bug
Metricbeat
Team:Elastic-Agent-Data-Plane
- Dominant language
- Go
- Stars
- 12.7k
- Forks
- 5k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 364
Description
On macOS, [`getProcArgs()`](https://github.com/elastic/elastic-agent-system-metrics/blob/31d43a646c5d986c77107ca770ee1b4467aad87c/metric/system/process/process_darwin.go#L172) allocates a fresh 1 MiB buffer on every call via `make([]byte, C.ARG_MAX)`. Because this function is called for every matched process on every collection cycle, the allocation rate can reach hundreds of MiB per second when monitoring all processes at a short interval. Under normal `GOMAXPROCS` settings the garbage collector keeps up.
When `GOMAXPROCS` is set to a lower number, the GC lags behind in freeing up memory and it leads to memory explosion.
Contributor guide
Assessment
This issue has not been assessed yet.