To learn about nginx performance optimization, I found articles on the Internet, "using TCMalloc to optimize nginx performance" and "using google-perftool to optimize nginx performance. I read these articles separately and found the same content.
In fact, google-perftools includes four tools: TCMalloc, heap-checker, heap-profiler, and cpu-profiler. TCMalloc is one of google-perftools tools, it is used to optimize the memory allocation efficiency and speed, and helps control the memory usage in high concurrency.
In mysql and nginx performance optimization solutions, most of the tutorials use the TCMalloc tool provided by google-perftools. The efficiency and speed of TCMalloc in memory allocation is much higher than that of malloc. However, nginx memory usage is actually very small, and a process occupies about 12 Mb of memory. Therefore, google-perftools may not significantly optimize nginx.
However, since we have this technology, we will learn how to use it.
Install and configure google-perftools
Before installation, determine whether the OS is 64-bit or 32-bit. If the OS is 64-bit, install the libunwind library before installing google-perftools:
1. [root @ lvs ~] # Uname-
2. Linux lvs. master 2.6.18-164. el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux
3. [root @ lvs ~] #
This indicates that my environment is a 32-bit environment. So the libunwind installation method should be searched by the officers themselves. (^ O ^ )/
1. Install google-perftools
1. [root @ lvs pkgs] # wget http://gperftools.googlecode.com/files/google-perftools-1.10.tar.gz
2. [root @ lvs google-perftools-1.10] #./configure
3. [root @ lvs google-perftools-1.10] # make & make install
4. [root @ lvs google-perftools-1.10] # echo "/usr/local/lib">/etc/ld. so. conf. d/usr_local_lib.conf
5. [root @ lvs google-perftools-1.10] # ldconfig
Ii. recompile nginx
1. [root @ lvs nginx-0.8.53] #./configure -- with-google_perftools_module -- with-http_stub_status_module
2. [root @ lvs nginx-0.8.53] # make & make install
3. Add a thread directory for google-perftools
1. [root @ lvs nginx] # mkdir/tmp/tcmalloc
2. [root @ lvs nginx] # chmod 0777/tmp/tcmalloc/
4. Modify the nginx configuration file
1. [root @ lvs nginx] # vim/usr/local/nginx/conf/nginx. conf
2. Add the following line:
3. google_perftools_profiles/tmp/tcmalloc;
4.
5. Restart nginx:
6. [root @ lvs nginx] # ps ax | grep nginx | grep-v grep | awk '{print $1}' | xargs kill-9
7. [root @ lvs nginx] #/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf
Here I encountered an error: Error prompt
1. [root @ lvs nginx] #/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf
2./usr/local/nginx/sbin/nginx: error while loading shared libraries: libprofiler. so.0: cannot open shared object file: No such file or directory
3. [root @ lvs nginx] #
Later I found that it was/etc/ld. so. conf. the d/usr_local_lib.conf file contains a problem. In this step, "echo"/usr/local/lib ">/etc/ld. so. conf. d/usr_local_lib.conf"
I copied an online article and later found garbled characters in the/etc/ld. so. conf. d/usr_local_lib.conf file. After the change, it will be normal. If you find the same errors as me,
Check whether the file is normal.
1. [root @ lvs lib] #/usr/local/nginx/sbin/nginx-V
2. nginx version: nginx/0.8.53
3. built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46)
4. configure arguments: -- with-google_perftools_module -- with-http_stub_status_module
5. Verification:
1. [root @ lvs lib] #/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx. conf
2. [root @ lvs lib] # lsof-n | grep tcmalloc
3. nginx 22171 nobody 10 w REG 985587/tmp/tcmalloc.22171
4. [root @ lvs lib] # head/usr/local/nginx/conf/nginx. conf
5. user nobody;
6. worker_processes 1;
A thread has a record file. Since I only open one thread, there is only one record file.
The configuration method optimized by google-perftools has been described.
This article is from the "YEELON ghost" blog