Use Google-perftools to optimize the performance of nginx in high concurrency. Full tutorial [version 2]

Source: Internet
Author: User

Nginx is very suitable for web sites because it is small and occupies less resources. More and more Linux + nginx + PHP + MySQL sites have gradually surpassed Apache and Lighttpd in recent years.

If Google-perftools developed by Googler is used to optimize the memory management of nginx and MySQL, the performance will be improved to a certain extent. especially for servers with high concurrency, the effect is more obvious. this tutorial is applicable only to Linux and not to Windows.

The following describes how to install Google-perftools and enable nginx and MySQL to support Google-perftools.

Today, we will first introduce how to optimize nginx:

1. First download and install Google-perftools:

Note: For a 64-bit system:

Then you need:
1) install libunwind first or 2) Add -- enable-frame-pointers during configure.

First, let's talk about how to install libunwind:

Wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
Tar zxvf libunwind-0.99.tar.gz
CD libunwind-0.99/
Cflags =-FPIC./configure -- prefix =/usr
Make cflags =-FPIC
Make cflags =-FPIC install

The installation of libunwind is complete.

If you want to add -- enable-frame-pointers, let's go down.

Download and install Google-perftools:

Wget http://google-perftools.googlecode.com/files/google-perftools-1.7.tar.gz
Tar xzvf google-perftools-1.7.tar.gz
CD google-perftools-1.7

Then start Configuration:
./Configure -- prefix =/usr-- Enable-frame-Pointers
Note that in this step, if it is a 32-bit system, you can not add -- enable-frame-pointers. If it is a 64-bit system, and you have not installed libunwind before, then you must add this: -- enable-frame-Pointers

Compile and install:

Make
Make install

The installation of Google-perftools has been completed but has not taken effect. Then, you need to make Google-perftools take effect:

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

Note that the double quotation marks are in English.

Google-perftools is installed here.

To make nginx support Google-perftools, you need to add -- with-google_perftools_module re-compile nginx, if you do not know how to install nginx, you can view nginx installation tutorial here.

For example:

./Configure -- user = WWW -- group = WWW -- prefix =/usr/local/nginx \
With-http_stub_status_module \
-- With-http_ssl_module -- With-OpenSSL = \
With-http_addition_module \
-- With-zlib = \
With-google_perftools_module

Make

Make install

Add a nginx restart script. download it from wpadm.com.

Nginx installation is complete.

 

Next, add the thread directory for Google-perftools:

Mkdir/tmp/tcmalloc
Chmod 0777/tmp/tcmalloc

Modify/usr/local/nginx/CONF/ncing. conf
Add below this line of PID
# PID logs/nginx. PID;
Google_perftools_profiles/tmp/tcmalloc;

Restart nginx:
Service nginx restart

Verify if it is running:

[Root @ localhost ~] # Lsof-N | grep tcmalloc
Nginx 13101 WWW 45 W Reg 4014748/tmp/tcmalloc.13101
Nginx 13102 WWW 47 W Reg 4014742/tmp/tcmalloc.13102
Nginx 13103 WWW 49 w Reg 4014746/tmp/tcmalloc.13103
Nginx 13105 WWW 51 W Reg 4014745/tmp/tcmalloc.13105
Nginx 13106 WWW 53 W Reg 4014743/tmp/tcmalloc.13106
Nginx 13107 WWW 55 W Reg 4014749/tmp/tcmalloc.13107
Nginx 13108 WWW 57 W Reg 4014754/tmp/tcmalloc.13108
Nginx 13109 WWW 59 W Reg 4014750/tmp/tcmalloc.13109
Nginx 13110 WWW 61 W Reg 4014747 1 0/tmp/tcmalloc.000010
Nginx 13111 WWW 63 W Reg 4014755/tmp/tcmalloc.11211
Nginx 13112 WWW 65 W Reg 4014753/tmp/tcmalloc.000012
Nginx 13113 WWW 67 W Reg 4014756 1 0/tmp/tcmalloc.11213
Nginx 13114 WWW 69 W Reg 4014757/tmp/tcmalloc.000014
Nginx 13115 WWW 71 W Reg 4014751/tmp/tcmalloc.000015
Nginx 13116 WWW 73 W Reg 4014744/tmp/tcmalloc.11216
Nginx 13117 WWW 75 W Reg 4014752/tmp/tcmalloc.13117

Because my server has 8 cores, eight nginx threads are enabled. Each thread has a line of similar records.

The installation and optimization are completed here.

Related Articles:
Google-perftools optimizes MySQL

Related reading:

  1. Google-perftools optimizes MySQL
  2. Linux + nginx + PHP + MySQL + memcached + eaccelerator installation optimization record

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.