对 python 程序进行内存性能分析,会带来 2,30% 左右的性能开销。
因此我们动态的开启和关闭它。
python 通常通过 gunicorn 启动多进程:
gunicorn -w 4
主进程监听在 12580 端口上。
只需要一个 http 请求就能够对所有 python 进程都进行内存性能分析。
curl http://ip:12580/debug/pprof/heap
通过火焰图可以直接查看到源代码。
通过每 1min 对测试环境的 python 进程采样,python 进程实现了持续的内存性能分析。