Starting from version v1.3.0g , jemalloc embedded in ProxySQL is compiled with —enable-prof
, allowing memory profiling.Memory profiling is disabled by default.
To enable profiling, it is required to restart proxysql with an environment variable MALLOC_CONF
to override the embedded/default jemalloc configuration.The current jemalloc configuration is xmalloc:true,lg_tcache_max:16,purge:decay
.To enable memory profiling, prof
and prof_leak
need to be enabled, while lg_prof_sample
and lg_prof_interval
need to be tuned.A suggested tuning for jemalloc memory profiler could be the follow:
"xmalloc:true,lg_tcache_max:16,purge:decay,prof:true,prof_leak:true,lg_prof_sample:18,lg_prof_interval:30"
Therefore, the environment variable should be:
MALLOC_CONF="xmalloc:true,lg_tcache_max:16,purge:decay,prof:true,prof_leak:true,lg_prof_sample:18,lg_prof_interval:30"
Details about jemalloc configuration can be found here.
Start ProxySQL with memory profiler
using init script
If you are running proxysql using init script /etc/init.d/proxysql
, it is enough to add the follow line before the point when the process is started, for example at around line 19 in /etc/init.d/proxysql
:
export MALLOC_CONF="xmalloc:true,lg_tcache_max:16,purge:decay,prof:true,prof_leak:true,lg_prof_sample:18,lg_prof_interval:30"
without init script
If you are running proxysql without init script /etc/init.d/proxysql
, you need to ensure that the environment variable is set before starting proxysql
. For example, if you run proxysql in foreground, you need to execute it similar to the following:
MALLOC_CONF="xmalloc:true,lg_tcache_max:16,purge:decay,prof:true,prof_leak:true,lg_prof_sample:18,lg_prof_interval:30" proxysql -f -c /etc/proxysql.cnf
How to report a memory leak?
jemalloc profiler will regularly write memory profile dumps in /var/lib/proxysql
, with names proxysql.<pid>.<seq>.i<iseq>.heap
.To report a memory leak, please create a tarball with the dumps generated by jemalloc profiler and either create an issue or drop me an email.Please also include which exact version of ProxySQL you are using, and on which OS:
- if you used an rpm or a deb package, specify which one exactly
- if you compiled proxysql yourself, include
proxysql
binary in the report
Disable profiling
To disable profiling, ProxySQL needs to be restarted without MALLOC_CONF
set.
原文: https://github.com/sysown/proxysql/wiki/Memory-leak-detection