Categories
Documentation MySQL

Using the Google Perftools to speed up your MySQL server

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, 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 :

export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.0"

/etc/init.d/mysql modification

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.

15 replies on “Using the Google Perftools to speed up your MySQL server”

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

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.)”

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.

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

@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!

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 🙂

Comments are closed.