Home > Article > Backend Development > Why Do Docker Stats and pprof Show Different Memory Usage in Go Applications?
Docker stats provides memory usage information from cgroups, while pprof focuses on the application's memory footprint. This mismatch occurs because:
Docker Stats Includes Temporary Memory:
Docker stats incorporates non-permanent memory like page cache and reserved memory (RES) into the "usage_in_bytes" metric. This can lead to inflated memory reports, especially for applications with file I/O.
Container Resource Management:
If a container reaches its memory limit, the kernel reclaims unused memory, enabling processes to continue running. This explains why docker stats initially show increasing memory usage, followed by a plateau when the limit is reached.
pprof's Runtime Memory:
pprof's "sys" memory statistic measures the application's actual memory usage, which is unaffected by page cache or RES. Hence, it may not reflect the full memory profile reported by docker stats.
How to Limit Container Resource Usage:
To constrain memory usage for docker containers, use the following methods:
By understanding this disparity, developers can accurately monitor their application's memory consumption and optimize resource utilization.
The above is the detailed content of Why Do Docker Stats and pprof Show Different Memory Usage in Go Applications?. For more information, please follow other related articles on the PHP Chinese website!