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…
First of all, be sure you use Debian 5.0 (a.k.a. “Lenny”) or later. Then install the minimal tcmalloc library from Dotdeb :
apt-get install libtcmalloc-minimal0
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 :
After relauching your MySQL server using the modified init script, you’ll take profit from tcmalloc’s faster memory allocation.
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.
15 replies on “Using the Google Perftools to speed up your MySQL server”
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
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 ^^)
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.
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.)”
Is there any chance that the perftools/amd64 problems will be fixed shortly?
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.
Version 0.99.2 released! What about releasing a new package? cheers!
@Guillaume : as soon as it appears in Sid, I think : http://packages.qa.debian.org/g/google-perftools.html
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?
@Mark : Finding the cause of this performance decrease is something very “touchy” from a Etch to Lenny, because many parameters change :
– libc6 and all libraries that MySQL uses evolved much.
– they’re not compiled using the same options
– the kernel changed
I advise you to change each parameter one by one to find which one is affecting the performances.
Thanks for all your hard work. Your PHP packages mean I can have bundled GD and your malloc stuff means my server’s a little (lot) leaner and meaner. Thanks!
debian 6 Whether to use this method.
[…] 关于libtcmalloc-minimal0请看Using the Google Perftools to speed up your MySQL server，据说能提升~15-20%的性能，未测试。 […]
I know that this is old topic. But i tested this with Debian 6 and i don’t get any erros, but not sure about speed up.
gperftools 2.1 est sorti le 30 Juillet 2013, c’est encore maintenu sur DotDeb ? Y-a-t-il encore un intérêt de l’utiliser avec MySQL ? Merci 🙂