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.
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
– 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.
# Test: POINT_SELECT:throughput, QPS
# Set 1 - 5.5.30pre-jemalloc-3.0.0
# Set 2 - 5.5.30pre-jemalloc-3.1.0
# Set 3 - 5.5.30pre-jemalloc-3.2.0
# Set 4 - 5.5.30pre-jemalloc-3.3.0
# Threads Set 1 Set 2 Set 3 Set 4
1024 236575.74 236862.59 211203.42 215098.20
2048 154829.26 154348.16 135607.69 137162.29