Note: This tutorial is only applicable to Linux.
The following describes how to install google-perftools and configure Nginx and MySQL to support google-perftools.
First, we will 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:
Copy codeThe Code is as follows: 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:
Copy codeThe Code is as follows: 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:
Copy codeThe Code is as follows:./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:
Copy codeThe Code is as follows: 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:
Copy codeThe Code is as follows: 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:
Copy codeThe Code is as follows:./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:
Copy codeThe Code is as follows: mkdir/tmp/tcmalloc
Chmod 0777/tmp/tcmalloc
Modify/usr/local/nginx/conf/ncing. conf
Add below this line of pid
Copy codeThe Code is as follows: # pid logs/nginx. pid;
Google_perftools_profiles/tmp/tcmalloc;
Restart nginx:
Copy codeThe Code is as follows: service nginx restart
Verify if it is running:
Copy codeThe Code is as follows: [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.
Finally, google-perftools under nginx has been optimized and installed for your reference.