Using the Google Perftools to speed up your MySQL server
August 25th, 2008 | by Guillaume Plessis |The Google Perftools, especially tcmalloc (Thread Caching Malloc), can be very useful to speed up your applications, depending on your environment :
TCMalloc is faster than the glibc 2.3 malloc (available as a separate library called ptmalloc2) and other mallocs that I have tested. ptmalloc2 takes approximately 300 nanoseconds to execute a malloc/free pair on a 2.8 GHz P4 (for small objects). The TCMalloc implementation takes approximately 50 nanoseconds for the same operation pair.
Its deployment in your LAMP stack can speed up your MySQL servers, since it enhances memory allocation on threaded applications with the downside of larger memory footprints.
Here is how to use it easily…
Installation
First of all, you can install Google Perftools from Dotdeb :
apt-get install libgoogle-perftools0
Then, since the mainstream MySQL packages are not compiled against tcmalloc, you’ll have to trick your OS’ dynamic linker by adding the following line at the top of your /etc/init.d/mysql init script :
export LD_PRELOAD="/usr/lib/libtcmalloc.so.0"
After relauching your MySQL server using the modified init script, you’ll take profit from tcmalloc’s faster memory allocation.
Results
At the time of writing this article, I didn’t make benchmarks, but some reported that they had a ~15-20% performance gain. Please leave comments about your experience.
Tags: google-perftools, MySQL, performance
9 Responses to “Using the Google Perftools to speed up your MySQL server”
By Mario on Aug 27, 2008 | Reply
Hi there,
I’ve tried it on a debian 4.0r4 etch with the mysql package from dotdeb. Unfortunately the mysql script return this:
dirname: symbol lookup error: /usr/lib/libtcmalloc.so.0: undefined symbol: pthread_key_create
basename: symbol lookup error: /usr/lib/libtcmalloc.so.0: undefined symbol: pthread_key_create
Any clues?
Regards,
Mario
By Mario on Aug 27, 2008 | Reply
Ok, got it working. I’ve used the 0.98 version from http://code.google.com/p/google-perftools/ which is also available as DEB and installed the DEV package also (don’t know if this really matters ^^)
Regards,
Mario
By Guillaume Plessis on Aug 27, 2008 | Reply
I’ll repackage the version 0.98 of Google perftools in a Dotdeb flavour as soon as I recover my amd64 build machine.
Please be patient.
By Guillaume Plessis on Sep 9, 2008 | Reply
Sorry, but after some tries, I won’t provide google-perftools on amd64, since it has some problem with libc6 :
“The glibc built-in stack-unwinder on 64-bit systems has some problems
with the perftools libraries. (In particular, the cpu/heap profiler
may be in the middle of malloc, holding some malloc-related locks when
they invoke the stack unwinder. The built-in stack unwinder may call
malloc recursively, which may require the thread to acquire a lock it
already holds: deadlock.)”
By Bert Slagter on Nov 1, 2008 | Reply
Is there any chance that the perftools/amd64 problems will be fixed shortly?
By Guillaume Plessis on Nov 6, 2008 | Reply
I just uploaded amd64 packages of google-perftools, that are linked to lubunwind to fix some of the amd64 issues.
Please make tests before deploying them in production and please send me feedbacks.
By Guillaume on Nov 6, 2008 | Reply
Version 0.99.2 released! What about releasing a new package? cheers!
By Guillaume Plessis on Nov 6, 2008 | Reply
@Guillaume : as soon as it appears in Sid, I think : http://packages.qa.debian.org/g/google-perftools.html
By mark on Nov 22, 2008 | Reply
Guillaume,
Wondering if you’ve seen this. I installed google-perftools on etch and had great improvement on mysql OLTP. However, following the same instruction and install it on lenny doesn’t seem to have any effect on the performance. If anything, performance on lenny actually degraded. Could you think of anything that might be causing this in Lenny?
thanks,
Mark