Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Google-perftools for nginx performance Optimization

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

What is google-perftools?

Google-perftools is an open source tool for performance analysis developed by google, which can be used to analyze the allocation and use of system resources such as CPU time slice and memory.

Google-perftools contains four tools, namely: TCMalloc, heap-checker, heap-profiler and cpu-profiler. One of the tools we need this time is TCMalloc, one of the tools of google-perftools, which is used to optimize the efficiency and speed of memory allocation and help to control the use of memory in the case of high concurrency.

Why do operators use google-perftools?

Use google-perftools developed by google to optimize the memory allocation efficiency and speed of nginx and mysql to help control memory usage in high concurrency situations. However, the memory footprint of nginx is actually very small, and the memory occupied by a process is only about 12m, so the optimization effect of google-perftools on nginx may not be obvious.

What is the TCMalloc tool?

As mentioned above, TCMalloc is a tool of google-perftools. Compared with the Malloc of the standard glibc library, the TCMalloc library has much higher memory allocation efficiency and speed, which greatly improves the performance of the server in high concurrency cases, thus reducing the system load on how to add TCMalloc library support for Nginx. To install the TCMalloc library, you need to install libunwind and gperftools software packages. Libunwind library provides basic function call chain and function call function register for programs based on 64 CPU operating system, and 32-bit operating system does not need to be installed.

Through the above three consecutive questions, we have a general idea of what google-perftools is, so we will proceed with how to install and use it.

Install the compilation tools:

Yum-y install gcc make

Yum-y install gcc gcc-c++

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

Install google-perftools:

Wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz

Tar zxvf gperftools-2.7.tar.gz

Cd gperftools-2.7

. / configure-- enable-frame-pointers-- enable-libunwind-- with-tcmalloc-pagesize=32

Or

. / configure-- enable-frame-pointers

Make & & make install

Note: if it is a 64-bit system, you need to install libunwind first, and then add the-- enable-frame-pointers parameter to configure gperftools.

Install nginx and add parameters

The installation of nginx is omitted. If nginx is installed before installing google-perftools, you need to consider whether to upgrade and restart smoothly. You can add parameters for smooth upgrade.

Example:. / configure-- prefix=/usr/local/nginx-- with-http_stub_status_module-- with-google_perftools_module

Although the above has been installed, it still cannot be used because this module is not added to the nginx configuration file.

1. Add thread directory

Mkdir / tmp/tcmalloc

Chmod 0777 / tmp/tcmalloc

two。 Make soft connections or reference dynamic libraries

Echo "/ usr/local/lib" > / etc/ld.so.conf.d/usr_local_lib.conf

/ sbin/ldconfig

3. Modify the nginx.conf configuration file to add the following information to the pid line to open the module

Google_perftools_profiles / tmp/tcmalloc

Then start or restart nginx

Just verify it.

Nginx 44112 nobody 10w REG 8,4 0 1044489 / tmp/tcmalloc.44112

A thread will have a record file, and since I have only one thread open, there is only one record file.

Extend:

Start nginx and find that the support of libprofiler.so.0 dynamic library is missing

/ usr/local/nginx/sbin/nginx

/ usr/local/nginx/sbin/nginx: error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory

This is because perftools achieves java application runtime through Linux's LD_PRELOAD, swapping its libtcmalloc.so when malloc is called

Find out whether there is a libprofiler.so.0 dynamic library under the system

Whereis libprofiler.so.0

Libprofiler.so: / usr/local/lib/libprofiler.so.0 / usr/local/lib/libprofiler.so

Since it is not in the directory looked up by the nginx program, you need to create a soft link

To assess the lack of dynamic library support, you can check the "not found" section through ldd / usr/local/nginx/sbin/nginx.

Ln-s / usr/local/lib/libprofiler.so.0.4.18 / lib64/libprofiler.so.0

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report