PHP+NGINX参数优化

# server 127.0.0.1:9001 weight=100 max_fails=10 fail_timeout=30;

# server 127.0.0.1:9002 weight=100 max_fails=10 fail_timeout=30;

# server 127.0.0.1:9003 weight=100 max_fails=10 fail_timeout=30;

server unix:/var/www/php-fpm.sock weight=100 max_fails=10 fail_timeout=30;

server unix:/var/www/php-fpm1.sock weight=100 max_fails=10 fail_timeout=30;

server unix:/var/www/php-fpm2.sock weight=100 max_fails=10 fail_timeout=30;

server unix:/var/www/php-fpm3.sock weight=100 max_fails=10 fail_timeout=30;

# server unix:/var/www/php-fpm4.sock weight=100 max_fails=10 fail_timeout=30;

# server unix:/var/www/php-fpm5.sock weight=100 max_fails=10 fail_timeout=30;

# server unix:/var/www/php-fpm6.sock weight=100 max_fails=10 fail_timeout=30;

# server unix:/var/www/php-fpm7.sock weight=100 max_fails=10 fail_timeout=30;

}

location ~ .php* {

fastcgi_pass phpbackend;

# fastcgi_pass unix:/var/www/php-fpm.sock;

fastcgi_index index.php;

...

}

6、测试环境和结果

内存2G

swap2G

cpu 2核 Intel(R) Xeon(R) CPU E5405 @ 2.00GHz

采用ab远程访问测试,测试程序为php的字符串处理程序

1)在开4个php-fpm实例,nginx 8个worker_processes 每个cpu4

worker_processes ,backlog为1024,php的backlog为2048,内核backlog为4096

采用unix domain socket连接的情况下,其他保持参数不变

性能和错误率较为平衡,可接受,超过4个fpm实例,性能开始下降,错误率并没有明显下降

结论是:fpm实例数,worker_processes数和cpu保持倍数关系,性能较高

影响性能和报错的参数为php-fpm实例,nginx worker_processes数量,fpm的 max_request,php的backlog,unix domain socket

 

10W请求,500并发无报错,1000并发报错率为0.9%

500并发:

Time taken for tests: 25 seconds avg.

Complete requests: 100000

Failed requests: 0

Write errors: 0

Requests per second: 4000 [#/sec] (mean) avg.

Time per request: 122.313 [ms] (mean)

Time per request: 0.245 [ms] (mean, across all concurrent requests)

Transfer rate: 800 [Kbytes/sec] received avg.

 

1000并发:

Time taken for tests: 25 seconds avg.

Complete requests: 100000

Failed requests: 524

(Connect: 0, Length: 524, Exceptions: 0)

Write errors: 0

Non-2xx responses: 524

Requests per second: 3903.25 [#/sec] (mean)

Time per request: 256.197 [ms] (mean)

Time per request: 0.256 [ms] (mean, across all concurrent requests)

Transfer rate: 772.37 [Kbytes/sec] received

2)在其他参数不变,unix domain socket换为tcp网络端口连接,结果如下

500并发:

Concurrency Level: 500

Time taken for tests: 26.934431 seconds

Complete requests: 100000



留言