Performance optimization Techniques for Nginx

Source: Internet
Author: User
Tags file size

optimization of compiling and installing process

1. Reduce the Nginx file size after compilation

When compiling nginx, the default is in debug mode, and in debug mode you insert a lot of information such as Trace and assert, and after the compilation completes, a nginx will have several megabytes. Cancel Nginx debug mode before compiling, nginx only kilometers byte after compiling, so you can revise the relevant source code and cancel debug mode before compiling, the specific method is as follows:

After the Nginx source file is uncompressed, locate the AUTO/CC/GCC file in the source directory, where you can find the following lines:

# Debug

Cflags= "$CFLAGS-G"

You can cancel the debug mode by commenting out or deleting these two lines.

2. Specify CPU type compilation optimizations for specific CPUs

When compiling nginx, the default gcc compilation parameter is "-O" and to optimize GCC compilation, you can use the following two parameters:

--with-cc-opt= '-o3 '

--WITH-CPU-OPT=CPU #为特定的 CPU compilation, valid values include: Pentium, Pentiumpro, Pentium3, Pentium4, Athlon, Opteron, AMD64, Sparc32, SPARC64, Ppc64

To determine the CPU type, you can use the following command:

[Root@localhost home] #cat/proc/cpuinfo | grep "model name"

Second, optimize the performance of Nginx using Tcmalloc

Tcmalloc, called Thread-caching Malloc, is a member of the Open Source Tool "Google-perftools" that Google has developed. Compared with the standard GLIBC Library's malloc, the Tcmalloc library is much higher in memory allocation efficiency and speed, which greatly improves the performance of the server under high concurrency, thus reducing the system load. The following is a brief description of how to add Tcmalloc Library support for Nginx.

To install the Tcmalloc library, you need to install Libunwind (32-bit operating systems do not need to be installed) and google-perftools two packages, Libunwind library provides basic function call chains and function call registers for programs based on 64-bit CPUs and operating systems. The following is a detailed procedure for optimizing nginx using Tcmalloc:

1. Install Libunwind Library

You can download the corresponding Libunwind version from Http://download.savannah.gnu.org/releases/libunwind, Here is the download libunwind-0.99-alpha.tar.gz, the installation process is as follows:

[Root@localhost home] #tar zxvf libunwind-0.99-alpha.tar.gz

[Root@localhost home]# CD libunwind-0.99-alpha/

[Root@localhost Libunwind-0.99-alpha] #CFLAGS =-fpic./configure

[Root@localhost Libunwind-0.99-alpha] #make cflags=-fpic

[Root@localhost Libunwind-0.99-alpha] #make cflags=-fpic Install

2. Install Google-perftools

The corresponding Google-perftools version can be downloaded from http://google-perftools.googlecode.com, where the google-perftools-1.8.tar.gz is downloaded and the installation process is as follows:

[Root@localhost home] #tar zxvf google-perftools-1.8.tar.gz

[Root@localhost home] #cd google-perftools-1.8/

[Root@localhost google-perftools-1.8]#./configure

[Root@localhost google-perftools-1.8] #make && make install

[Root@localhost google-perftools-1.8] #echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf

[Root@localhost google-perftools-1.8]# Ldconfig

At this point, the Google-perftools installation is complete.

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.