Operations 4 min read

Boost Nginx Performance with TCMalloc: Step‑by‑Step Installation Guide

This guide explains what TCMalloc is, lists required packages, and provides step‑by‑step commands to install libunwind and gperftools, compile Nginx with the Google perftools module, configure profiling directories, modify the Nginx config, and verify that TCMalloc is correctly loaded to improve server performance.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Nginx Performance with TCMalloc: Step‑by‑Step Installation Guide

TCMalloc Overview

TCMalloc (Thread‑Caching Malloc) is an open‑source memory allocator from Google’s perftools, offering higher allocation efficiency and speed than the standard glibc malloc, which improves server performance under high concurrency.

To add TCMalloc support to Nginx you need to install the libunwind and gperftools packages. libunwind provides call‑stack support on 64‑bit systems; it is not required on 32‑bit.

Required Packages

libunwind – official site: http://www.nongnu.org/libunwind/; download: http://down.shshenchu.com/libunwind-1.1.tar.gz

gperftools – official site: http://code.google.com/p/gperftools/downloads/list; download: http://down.shshenchu.com/gperftools-2.1.tar.gz

Installation Steps

1. Install libunwind

wget http://down.shshenchu.com/libunwind-1.1.tar.gz
tar -zxvf libunwind-1.1.tar.gz
cd libunwind-1.1
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

2. Install gperftools

wget http://down.shshenchu.com/gperftools-2.1.tar.gz
tar -zxvf gperftools-2.1.tar.gz
cd gperftools-2.1
./configure
make && make install
echo "/usr/local/lib" >> /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig

3. Compile Nginx with TCMalloc

When configuring Nginx add the option --with-google_perftools_module.

4. Create a directory for TCMalloc profiling data

mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc

5. Modify Nginx configuration

Add the following line after the pid directive:

google_perftools_profiles /tmp/tcmalloc;

6. Verify that TCMalloc is loaded

Run:

lsof -n | grep tcmalloc

The output should show Nginx processes with open files under /tmp/tcmalloc, confirming that the profiler is active.

Following these steps completes the TCMalloc optimization of Nginx.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxTCMallocgperftools
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.