MySQL performance: Impact of memory allocators (Part 2)

Last time I wrote about memory allocators and how they can affect MySQL performance in general. This time I would like to explore this topic from a bit different angle: What impact does the number of processor cores have on different memory allocators and what difference we will see in MySQL performance in this scenario?

Let me share a conclusion first: If you have a server with more than 8 cores you should use something different than the default glibc memory allocator.
We recommend jemalloc or tcmalloc

In my test I will use Dell R720 box(spec), Centos 6.3, upcoming Percona Server 5.5.30 and 3 allocators – stock glibc 2.13, jemalloc-3.1.0, the latest tcmalloc from svn repo. Regarding my selection of jemalloc version see my notes at the end of this post.

Test box has 2xIntel E5/2.2Ghz with 8 real cores per socket – 16 real cores + enabled hyper-threading gives us total – 32 vcpu. In my tests I didn’t see any notable difference between allocators up to 4 vcpu, so on charts below I will highlight results from 4 to 32 vcpu.

As test workload I will use the same 2 sysbench tests – OLTP_RO and POINT_SELECT that I used before.
Sysbench dataset – 16 tables, each 5M rows, uniform distribution.

OLTP_RO test consists of 5 select queries – select_ranges, select_order_ranges, select_distinct_ranges, select_sum_ranges, point_select. Processing these queries will involve notable amount of malloc()/free() operations, so allocator efficiency is the key factor to achieve high throughput in this test.



  • 4 vcpu – results are almost identical for all allocators (~2500tps)
  • 8 vcpu – results doubled (~5000tps) for jemalloc and tcmalloc, but with glibc malloc we have a drop at 64/128 threads to ~3500tps
  • 16vcpu – increase in throughput and quite stable results for jemalloc and tcmalloc up to 4096 threads (~6300tps) and again drop after 16 threads for glibc to ~4000tps
  • 32vcpu – throughput for jemalloc and tcmalloc jumped to ~12500tps, results stay at this level up to 1024 threads and then tps slightly decreased but still looks ok. For glibc tps drops below results we have observed for 8/16 vcpu(~3100tps).

So difference in OLTP_RO test between glibc and jemalloc/tcmalloc in case of 32vcpu is ~4x.

POINT_SELECT – very simple query – SELECT c FROM sbtest WHERE id=N. Test workload with this query
allows to generate significant load and check server behavior under very high pressure



  • 4 vcpu – again no difference between allocators (~50,000qps)
  • 8 vcpu – with all allocators we got ~100,000qps. Results for jemalloc/tcmalloc are stable up to 4096 threads, for glibc malloc there is decrease in qps for 2048/4096 threads to ~80.000qps.
  • 16vcpu – with all allocators we got ~140,000qps. For jemalloc/tcmalloc up to 4096 threads, for glibc up to 512 threads, then decrease in throughput to 100,000qps.
  • 32vcpu – with all allocators we got up to ~240,000qps. Then for every allocator we have drop in throughput but at different point and to different level.
    – for glibc malloc drop happened after 256 threads, qps is below the level for 8/16 vcpu. (~80,000qps).
    – for tcmalloc drop happened after 1024 threads, at 2048 thread qps is very close to results for 16vcpu and at 4096 threads qps is ~17,000.
    – for jemalloc drop happened after 1024 threads as well, at 2048 thread qps is very close to results for 16vcpu and at 4096 threads – qps is slightly better than results for 4vcpu (~60,000qps).As you can see in the case of the very high concurrency and notable amount of the small/medium allocations, we have quite poor results for jemalloc/tcmalloc. Even worse than for glibc. This is the very specific case when overhead from the advanced techniques used in these allocators that should help to speed up allocation,purging of the dirty pages, minimize impact of the memory fragmentation is so significant that becomes bottleneck for the query processing. I believe that both allocators can be tuned to handle such cases better – for instance allocate more arenas but that may notably increase memory footprint.

– if your box has 8 cores or less – there is almost no difference between glibc malloc and alternative allocators
– if your box has more than 8 cores – you should try/evaluate alternative allocators; it can notably boost your MySQL server at no cost. Also, an alternative allocator must be used if you run benchmarks in this configuration, otherwise the performance will be limited by glibc/malloc and not by MySQL.

Notes regarding jemalloc version I’ve used in my tests: I’ve noted notable impact on MySQL performance after version 3.2.0 (see raw results below) so I used jemalloc-3.1.0 in my tests. I suppose that some changes in 3.2.0 like for instance changes re: page run allocation and dirty page purging may have some correlation with decreasing performance in workloads with MySQL.

Share this post

Comments (14)

  • Hubertus Krogmann


    The first question comes to mind: how do I change the allocator?
    Get the source and do make;make install, or is there an easier way?


    March 8, 2013 at 11:05 am
  • Matthew Montgomery

    He mentions how to use these in a previous post:

    You just need to use LD_PRELOAD to load that library.

    March 8, 2013 at 11:15 am
  • Nils

    Shouldn’t there be some effort to improve the glibc allocator?

    March 8, 2013 at 11:32 am
  • Alexey Stroganov


    You can get binary packages for jemalloc and tcmalloc from Centos repos or just get the sources, build and install libraries.

    Regarding usage – either prefix mysqld with LD_PRELOAD – LD_PRELOAD=[/path/to/library/] mysqld … or you can use –malloc-lib option for mysqld_safe script. You can also add this as variable to [mysqld_safe] section of my.cnf.

    March 8, 2013 at 12:12 pm
  • Bradley C Kuszmaul

    We use jemalloc in TokuDB for these reasons, and also because the memory footprint is smaller. The newer allocators, such as jemalloc and tcmalloc, do much better on long-running processes at managing physical memory. For a long running process, like mysqld, glibc seems to fragment physical memory, so that glibc actually requires substantially more memory.

    March 8, 2013 at 1:31 pm
  • Vadim Tkachenko


    This is more question to glibc developers.
    They made significant changes into MEMORY ARENAS and I guess they did not fully think through how it affects all workloads.

    Another problem is that glibc fixes some issue, i.e. there are fixes in glibc 2.16, but big distros
    are attached to fixed version, i.e RedHat 6.x uses glibc 2.15

    March 8, 2013 at 2:44 pm
  • tobi

    a) why doesn’t mysql ship with one of the better allocators?
    b) why doesn’t glibc scrap their allocator and import one of the better ones into their source tree?

    March 8, 2013 at 4:29 pm
  • Sadao Hiratsuka

    MySQL binary distribution such as mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz has in lib/ directory.
    MySQL RPM package for RHEL 5 (MySQL-server-5.6.10-1.rhel5.x86_64.rpm) has, too.
    But, MySQL RPM package for RHEL 6 (MySQL-server-5.6.10-1.el6.x86_64.rpm) does not have it.

    I think gcc malloc became more better in RHEL 6, so MySQL team eliminated
    If gcc malloc still has poor performance, we can report it to include into RHEL 6 RPMs.

    March 8, 2013 at 7:16 pm
  • tobi

    Ok in some distros it is available but why not always? Why doesn’t glibc physically delete their inferior code and replace it with one of the existing better alternatives?

    March 9, 2013 at 4:40 am
  • Vadim Tkachenko


    you are asking this in a wrong place.
    You may go and file a bug report to glibc developers (actually we may do it also).

    My previous report on ext4 vs xfs
    resulted that the fix for XFS is included in RedHat/CentOS 6.4

    March 9, 2013 at 2:43 pm
  • Kenta Tada

    I think the reason of drops may be because jemalloc uses per-thread mmaped arena instead of centralized heap.

    POINT_SELECT has very high tps results compared to other benchmarks.
    And so,
    I think the number of mmap systemcalll execution is related to those results.

    March 10, 2013 at 4:30 am
  • Hander

    Could Jemalloc improve performance no MySQL 5.6 on Windows 64-bit?

    How could we use Jemalloc on Windows 64-bit without compiling MySQL 5.6 source code with it?

    Thanks! Great article!!

    March 22, 2013 at 7:46 pm
  • bob

    Is this true on FreeBSD as well?

    June 9, 2014 at 12:02 am
  • naveen

    how to add the LD_PRELOAD ??

    October 27, 2016 at 8:12 am

Comments are closed.

Use Percona's Technical Forum to ask any follow-up questions on this blog topic.