默认编译jemalloc没开启prof功能,要自己开启后编译。
wget https://github.com/jemalloc/jemalloc/archive/5.1.0.tar.gz
tar zxvf 5.1.0.tar.gz
cd jemalloc-5.1.0/
./autogen.sh
./configure --prefix=/usr/local/jemalloc-5.1.0 --enable-prof
make -j
make install
设置环境变量
"MALLOC_CONF": "prof:true,lg_prof_interval:32,prof_prefix:/home/admin/logs/jeprof.out",
"LD_PRELOAD": "/tmp/libjemalloc.so.2"
安装依赖
sudo yum install ghostscript graphviz jemalloc-devel -y
在节点的logs目录中可以看到jeprof的输出:
有了jeprof文件,我们可以运行jeprof命令来查看两次snapshot之间的diff:
# 安装依赖(只需一次)
sudo yum install ghostscript graphviz jemalloc-devel -y
jeprof --pdf --base=jeprof.out.322606.197.i197.heap /usr/local/python3/bin/python3.7 jeprof.out.322606.221.i221.heap > 37066_197_221.pdf
然后分析单次snapshot的内存消耗
jeprof --pdf /usr/local/python3/bin/python3.7 jeprof.out.322606.221.i221.heap > 322606_221.pdf