VPS Small Memory Optimization Method Summary (Linux/nginx)

Source: Internet
Author: User
Tags fpm memory usage vps

First use: PS aux to view the memory usage of each process.

Reboot/shutdown of PHP-FPM

The PHP-FPM in PHP 5.3.3 no longer supports PHP-FPM previously available commands such as/USR/LOCAL/PHP/SBIN/PHP-FPM (Start|stop|reload), which require signal control:

The master process can understand the following signals

INT, TERM immediately terminated

QUIT Smooth Termination

USR1 Reopen the log file

USR2 smooth overload of all worker processes and reload configuration and binary modules

Example:

The code is as follows Copy Code

PHP-FPM off:

Kill-int ' Cat/usr/local/php/var/run/php-fpm.pid '

PHP-FPM reboot:

KILL-USR2 ' Cat/usr/local/php/var/run/php-fpm.pid '

To view the number of PHP-FPM processes:

PS aux | Grep-c PHP-FPM

***************************************************************

Php-fpm4 the meaning of a parameter is:

Pm.max_children: The number of PHP-FPM processes that are open in static mode.

Pm.start_servers: The number of starting PHP-FPM processes in dynamic mode.

Pm.min_spare_servers: The minimum number of PHP-FPM processes under dynamic mode.

Pm.max_spare_servers: The maximum number of PHP-FPM processes under dynamic mode.

If the DM is set to static, then only pm.max_children this parameter is in effect. The system will turn on the set number of PHP-FPM processes.

If the DM is set to dynamic, then the Pm.max_children parameter fails and the following 3 parameters take effect.

The system starts the Pm.start_servers PHP-FPM process at the start of the PHP-FPM run.

Then the number of php-fpm processes between Pm.min_spare_servers and Pm.max_spare_servers is dynamically adjusted according to the requirements of the system

The code is as follows Copy Code

Request_terminate_timeout = 120

#表示等待120秒后, end those PHP scripts that do not end automatically to release the resources that are occupied.

My Settings

The code is as follows Copy Code

Pm.start_servers = 5

Pm.min_spare_servers = 2

Pm.max_spare_servers = 15

A Nginx optimization method is attached below.

Open only one process

Nginx each process consumes memory, may have 10M to 15M, small memory will only open one save memory

Worker_processes 1;
Turn on gzip compression

On the Web page files, CSS, JS and so on to open gzip booth, reduce data transmission, reduce disk I/O, reduce memory exchange, save memory to improve access speed.

gzip on;

Gzip_min_length 1k;

Gzip_buffers 4 16k;

Gzip_http_version 1.1;

Gzip_comp_level 2;

Gzip_types text/plain application/x-javascript text/css application/xml;

Gzip_vary on;
Change fastcgi communication mode

Change the Nginx fastcgi communication to a UNIX Socket. TCP is stable under high concurrency, but slower than UNIX sockets.

The code is as follows Copy Code

#fastcgi_pass 127.0.0.1:9000;

Fastcgi_pass Unix:/tmp/php-cgi.sock;

Fastcgi_index index.php;

Include fcgi.conf;

Cache partial Files

such as pictures, CSS, JS is not often updated is the file can be cached in the browser.

  code is as follows copy code

Location ~. * . (GIF|JPG|JPEG|PNG|BMP|SWF|FLV|ICO|CSS|JS) ${

    expires 30d;

}

Related Article

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.