One of the statically linked libraries embedded in ProxySQL is jemalloc. jemalloc is compiled with --enable-prof, allowing memory profiling.
Since ProxySQL 1.4.0 memory profiling is enabled by default , but deactivated , allowing the activation at runtime.

Activate memory profiler at runtime

To activate the jemalloc profiler in ProxySQL it’s enough to connect to Admin interface, and execute the following command:


PROXYSQL MEMPROFILE START

After executing this command, ProxySQL will start writing profile dumps with names proxysql.<pid>.<seq>.i<iseq>.heap in one of the following two locations:

  • If executed in foreground (i.e. with -f, –foreground command line option). The files will be written in the folder from which ProxySQL is executed.
  • If executed in background (i.e. without -f, –foreground option) or via the init script the files will be written in ProxySQL specified datadir, which by default is /var/lib/proxysql.

After all the desired data has been collected, to stop memory profiling, ProxySQL needs to be restarted.

How to report a memory leak?

To report a memory leak:

  1. Start ProxySQL with memory profiling enabled and collect memory dumps until being certain that the leak is consuming a representative enough ammount of memory.
    • Please note that even if the leak is present, finding it without having enough profiling data could be very tricky. As it could hide behind the allocation patterns of a particular workload.
  2. Please create a tarball with the dumps generated by jemalloc profiler and either create an issue following the issue template at ProxySQL GitHub issues page.

Legacy: Profiling before ProxySQL v1.4.0

Using init script

If you are running ProxySQL using init script /etc/init.d/proxysql , it is enough to add the following 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 the 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

Disable profiling

To disable profiling, ProxySQL needs to be restarted without MALLOC_CONF set.

jemalloc and retained memory (not a leak)

Depending from workloads and different memory usage patterns, it is possible that ProxySQL virtual memory becomes high but resident memory is relatively small. This can also be verified in stats_memory_metrics , when jemalloc_retained has a value considerably higher than jemalloc_resident . Please note that this is not a memory leak, but a normal and expected behavior: jemalloc retains memory for further use.

jemalloc behavior can be controlled turning retain off , but this cannot be done at runtime.

Therefore it is required to start ProxySQL with the following environment variable set:

MALLOC_CONF="retain:false"