Spring boot application not using jemalloc

2019-06-10 06:33发布

I am trying to find out a memory leak issue. I am following this article and trying to use jemalloc

The steps followed are:

export LD_PRELOAD=/usr/local/lib/libjemalloc.so
export MALLOC_CONF=prof:true,lg_prof_interval:30,lg_prof_sample:17
sudo java -jar application.jar

However there is no .heap file created. I cannot find libjemalloc.so in pmap -x result. How can I ensure that the jvm is using jemalloc? Server is an ubuntu server and the application is using spring boot.

1条回答
我命由我不由天
2楼-- · 2019-06-10 07:10

When you run sudo, Java gets root environment which does not have your previously exported LD_PRELOAD and MALLOC_CONF.

Try

sudo LD_PRELOAD=/usr/local/lib/libjemalloc.so \
     MALLOC_CONF=prof:true,lg_prof_interval:30,lg_prof_sample:17 \
     java -jar application.jar

BTW, jemalloc is not always useful for profiling Java applications, since it cannot show Java stacks (but it is useful for preventing memory leaks caused by the standard allocator).

Try async-profiler as described in this answer.

Also check this post about Java native memory consumption.

查看更多
登录 后发表回答