Tutorial of full version that optimizes nginx's performance at high concurrency using google perftools

  • 2020-05-06 12:17:20
  • OfStack

Note: this tutorial is for Linux only.

Here's how to install google-perftools and configure Nginx and MySQL to support google-perftools.

First, how to optimize Nginx:

1, first download and install google-perftools:

Note that if you have a 64-bit system :

So what you need to do :
1) install libunwind first or 2) add -- enable-frame-pointers.

at configure

So first, 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

Go here and install libunwind.

If we're going to add -- enable-frame-pointers, forget it, 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 configuring :


./configure --prefix=/usr --enable-frame-pointers

If it's a 32-bit system, you don't need to add -- enable-frame-pointers. If it's a 64-bit system, and you didn't install libunwind before, you must add this :-- enable-frame-pointers

Compile and install :


make
make install

Go here and install google-perftools completed but not in effect, next you need to make es1064en-perftools in effect :


echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig

Note that the double quotes here are in English.

Go here and install google-perftools.

To make Nginx support google-perftools, you need to add -- with-google_perftools_module to recompile Nginx. If you don't know how to install Nginx, you can see the 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

To add the Nginx quick restart script, download.
from wpadm.com Go here and install Nginx.

Next, add the threads directory for google-perftools :


mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc

Modify/usr/local/nginx/conf/ncing conf
Add
below the pid row


#pid   logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;

Restart nginx:

service nginx restart

Verify that it is running :


[root@localhost ~]# lsof -n | grep tcmalloc
nginx     13101    www   45w      REG                8,1          0    4014748 /tmp/tcmalloc.13101
nginx     13102    www  47w      REG                8,1          0    4014742 /tmp/tcmalloc.13102
nginx     13103    www   49w      REG                8,1          0    4014746 /tmp/tcmalloc.13103
nginx     13105    www   51w      REG                8,1          0    4014745 /tmp/tcmalloc.13105
nginx     13106    www   53w      REG                8,1          0    4014743 /tmp/tcmalloc.13106
nginx     13107    www   55w      REG                8,1          0    4014749 /tmp/tcmalloc.13107
nginx     13108    www   57w      REG                8,1          0    4014754 /tmp/tcmalloc.13108
nginx     13109    www   59w      REG                8,1          0    4014750 /tmp/tcmalloc.13109
nginx     13110    www   61w      REG                8,1          0    4014747 /tmp/tcmalloc.13110
nginx     13111    www   63w      REG                8,1          0    4014755 /tmp/tcmalloc.13111
nginx     13112    www   65w      REG                8,1          0    4014753 /tmp/tcmalloc.13112
nginx     13113    www   67w      REG                8,1          0    4014756 /tmp/tcmalloc.13113
nginx     13114    www  69w      REG                8,1          0    4014757 /tmp/tcmalloc.13114
nginx     13115    www   71w      REG                8,1          0    4014751 /tmp/tcmalloc.13115
nginx     13116    www   73w      REG                8,1          0    4014744 /tmp/tcmalloc.13116
nginx     13117    www   75w      REG                8,1          0    4014752 /tmp/tcmalloc.13117


My server has 8 cores, so I have 8 Nginx threads open, and each thread will have a similar row of records.
As a result, the optimized installation of google-perftools under nginx has been completed, for friends' reference.


Related articles: