Boost Nginx Performance with TCMalloc: Step-by-Step Linux Installation Guide
This tutorial explains how to install TCMalloc and integrate it with Nginx on a Linux server, covering required dependencies, recompiling Nginx with the perftools module, configuring profiling directories, handling library errors, and extending the optimization to MySQL.
Integrating TCMalloc with Nginx on Linux
TCMalloc (Thread‑Caching Malloc) is an open‑source memory allocator from Google‑perftools that offers higher allocation speed than the standard glibc malloc, improving server performance under high concurrency.
Installation steps:
1. Install libunwind (if 64‑bit)
[root@htuidc src]# wget http://ftp.twaren.net/Unix/NonGNU//libunwind/libunwind-1.1.tar.gz
[root@htuidc libunwind-1.1]# CFLAGS=-fPIC ./configure
[root@htuidc libunwind-1.1]# make CFLAGS=-fPIC2. Install gperftools
[root@htuidc src]# wget https://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
[root@htuidc src]# tar zxvf gperftools-2.1.tar.gz
[root@htuidc src]# cd gperftools-2.1
[root@htuidc gperftools-2.1]# ./configure
[root@htuidc gperftools-2.1]# make && make installAfter these commands, google‑perftools is installed.
3. Recompile Nginx with the perftools module
[root@htuidc nginx-1.5.4]# ./configure --with-google_perftools_module --with-http_stub_status_module --prefix=/usr/local/nginx1.5
[root@htuidc nginx-1.5.4]# make && make installNginx is now built with TCMalloc support.
4. Create a directory for perftools thread profiles
[root@htuidc nginx-1.5.4]# mkdir /tmp/tcmalloc
[root@htuidc nginx-1.5.4]# chmod 0777 /tmp/tcmalloc5. Modify nginx.conf
Add the following line after the pid directive: google_perftools_profiles /tmp/tcmalloc; Restart Nginx. If you encounter “libprofiler.so.0” or “libunwind.so.8” errors, create symbolic links to the libraries in /lib or /lib64 as shown:
[root@htuidc conf]# ln -s /usr/local/lib/libprofiler.so.0 /lib/
[root@htuidc conf]# ln -s /usr/local/lib/libprofiler.so.0 /usr/lib/
[root@htuidc conf]# ln -s /usr/local/lib/libunwind.so.8 /lib64
[root@htuidc conf]# ln -s /usr/local/lib/libunwind.so.8 /usr/lib64Verify the module loads with: [root@htuidc lib64]# lsof -n|grep tcmalloc Each Nginx worker creates a file under /tmp/tcmalloc containing its PID.
Finally, to apply TCMalloc to MySQL, add export LD_PRELOAD=/usr/local/lib/libtcmalloc.so to the MySQL startup script and restart the service.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
