Use tcmalloc to optimize nginx Performance

Source: Internet
Author: User

Technical description:

Tcmalloc, short for thread-cachig malloc, is a member of Google-preftools, an open-source tool developed by Google. Compared with the standard glibc library's malloc, The tcmalloc library has much higher memory allocation efficiency and speed, greatly improving the server's performance in high concurrency, this reduces the system load.

1. Install libunwind:

1. Install libunwind:

Http://download.savannah.gnu.org/releases/libunwind/

Download libunwind-0.99.tar.gz

2. Tar-zxvf libunwind-0.99.tar.gz

3. CD libunwind-0.99

4. cflags =-FPIC./configure

5. Make cflags =-FPIC

6. Make cflags =-FPIC install

7. Echo "/usr/local/lib">/etc/lD. So. conf. d/usr_local_lib.conf

8./sbin/ldconfig

2. Install Google-preftools:

1 .:

Http://download.chinaunix.net/download.php? Id = 32582 & resourceid = 12865

Download google-perftools-1.9.tar.gz

2. chmod 700 google-perftools-1.9.tar.gz

3. Tar-zxvf google-perftools-1.9.tar.gz

4. CD google-perftools-1.9

5 ../configure

6. Make & make install

7. Echo "/usr/local/lib">/etc/lD. So. conf. d/usr_local_lib.conf

8./sbin/ldconfig

Iii. recompile nginx:

1. CD nginx-1.5.8

2 ../configure -- with-google_perftools_module -- user = WWW -- group = WWW -- prefix =/usr/local/nginx -- with-http_stub_status_module

3. Make & make install

4. Add a thread directory for Google-perftools:

Mkdir-P/tmp/tcmalloc

Chmod 0777/tmp/tcmalloc

5. Modify the nginx main configuration file:

Vim/usr/local/nginx/CONF/nginx. conf:

# PID logs/nginx. PID;

Google_perftools_profiles/tmp/tcmalloc;

6. Verify that Google-perftools is loaded normally. The command view method is as follows:

Lsof-N | grep tcmalloc

[[Email protected] conf] # lsof-N | greptcmalloc

Nginx 15017 WWW 10 W Reg 253,0 0 801420/tmp/tcmalloc.15017

Nginx 15018 WWW 12 W Reg 253,0 0 801417/tmp/tcmalloc.15018

Nginx 15019 WWW 14 W Reg 253,0 0 801415/tmp/tcmalloc.15019

Nginx 15020 WWW 16 W Reg 253,0 0 784898/tmp/tcmalloc.15020

Nginx 15021 WWW 18 W Reg 253,0 0 801274/tmp/tcmalloc.15021

Nginx 15022 WWW 20 W Reg 253,0 0 801414/tmp/tcmalloc.15022

Nginx 15023 www 22 W Reg 253,0 0 801418/tmp/tcmalloc.15023

Nginx 15024 WWW 24 W Reg 253,0 0 801419/tmp/tcmalloc.15024

In the main nginx configuration file nginx. conf, set worker_processes to 8. Therefore, eight nginx threads are enabled and each thread has a row of records. The numeric value after each thread file is the pid value of the started nginx.

Using tcmalloc to optimize nginx can improve the performance of servers in high concurrency, reduce system load, and ensure stable and efficient server operation!


This article from the "Lin Xi" blog, please be sure to keep this source http://lutaoxu.blog.51cto.com/4224602/1551374

Use tcmalloc to optimize nginx Performance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.