PHP-FPM installation is simple, see PHP (PHP-FPM) manual compilation installation. The following is mainly about how to improve the performance of NGINX+PHP-FPM.
1.Unix domain Socket communication A brief introduction to UNIX domain socket this way of communication, see: NGINX+PHP-FPM Socket Configuration method
UNIX domain sockets do improve the performance of Nginx and PHP-FPM communications because they do not go to the network, but they can be unstable when concurrency is high. Nginx will frequently complain: connect () to Unix:/dev/shm/php-fcgi.sock failed (11:resource temporarily unavailable) while connecting T o Upstream
There are two ways to improve stability: 1 The backlog configuration method in Nginx and PHP-FPM is: Under Server for this domain name in nginx configuration file, add default listen after backlog=1024 80. The Listen.backlog in the configuration php-fpm.conf is 1024, and the default is 128. 2 Add sock file and php-fpm instance number, then create a new sock file, in Nginx through the upstream module to balance the request load to two sock files behind the two sets of PHP-FPM instance.
2.PHP-FPM parameter Tuning 2.1 Number of processes PHP-FPM Initial/idle/maximum number of worker processes Pm.max_children = Pm.start_servers = Pm.min_spare_servers = 5 pm.max_s Pare_servers = 35
2.2 Maximum number of processing requests The maximum number of processing requests means that a PHP-FPM worker process terminates after processing as many requests, and the master process respawn a new one. The primary purpose of this configuration is to avoid memory leaks caused by Third-party libraries referenced by PHP interpreters or programs. Pm.max_requests = 10240
2.3 Maximum Execution time The maximum execution time can be configured in both PHP.ini and php-fpm.conf, and the configuration items are Max_execution_time and request_terminate_timeout respectively. Its effect and its effect see also: Nginx 502 and 504 error detailed
3.php-fpm High CPU usage Troubleshooting method 3.1CPU Use rate monitoring method 1 if the top command executes the top command directly, the CPU usage of each core can be seen by entering 1. And the sampling time can be shortened by top-d 0.1. The following SAR seems to be the shortest possible only 1 seconds.
2 SAR command SAR and iostat command installation: Sysstat.x86_64:The SAR and iostat system monitoring commands Yum install-y sysstat.x 86_64
Executive Sar-p all 1 100. -p all means to monitor all cores, 1 for every 1 seconds, and 100 for 100 times. The output results are as follows: Cpu %user %nice %system %iowait %steal %idle all 85.54 0.00 5.69 0.00 0.00 8.76 0 74.75 0.00 25.25 0.00 0.00 0.00 1 98.00 0.00 2.00 0.00 0.00 0.00 2 89.22 0.00 3.92 0.00 0.00 6.86 3 91.00 0.00 2.00 0.00 0.00 7.00 4 75.00 0.00 9.00 0.00 0.00 16.00 5 94.95 0.00 5.05 0.00 0.00 0.00 6&NBsp; 95.00 0.00 4.00 0.00 0.00 1.00 7 87.88 0.00 4.04 0.00 0.00 8.08 8 93.94 0.00 3.03 0.00 0.00 3.03 9 88.00 0.00 3.00 0.00 0.00 9.00 10 89.11 0.00 2.97 0.00 0.00 7.92 11 82.35 0.00 3.92 0.00 0.00 13.73 12 73.27 0.00 7.92 0.00 0.00 18.81 13 81.44 0.00 4.12 0.00 0.00 14.43 14 77.23 0.00 6.93 0.00 0.00 15.84 15 78.79 0.00 4.04 0.00 0.00 17.17
3.2 Open Slow log Configure output PHP-FPM slow log with a threshold of 2 seconds: request_slowlog_timeout = 2 Slowlog = log/$pool. Log.slow
Analyze the rollup using the Sort/uniq command php-fpm slow log: [root@b28-12 log]# grep-v "^$" www.log.slow.tmp | Cut-d ""-F 3,2 | Sort | uniq-c | SORT-K1,1NR | Head-n 5181 Run ()/www/test.net/framework/web/filters/cfilter.php:41
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.