# Bad perfomance with nginx and php-fpm

**URL:** <https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972>\
**Category:** NGINX\
**Created:** [November 17, 2011, 6:28pm UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972 "2011-11-17T18:28:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 17, 2011, 6:28pm UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/1 "2011-11-17T18:28:53Z")

</div>

Hello,

i’m trying to install nginx with php-fpm. It works, but it’s not  
really fast and i have problems with multiple connections.

Versions:  
nginx: nginx version: nginx/1.0.10  
PHP 5.3.8-1~dotdeb.2 (fpm-fcgi) (built: Aug 25 2011 13:36:54)

Configs:  
VHost:  
[…]  
location ~ .php$ {  
fastcgi\_index index.php;  
include /etc/nginx/fastcgi\_params;  
fastcgi\_param SCRIPT\_FILENAME /web$fastcgi\_script\_name;  
fastcgi\_pass unix:/tmp/foo.socket;  
}  
[…]

php5-fpm:  
[…]  
listen = ‘/tmp/foo.socket’  
user = foo  
group = foo  
pm = dynamic  
pm.max\_children = 10  
pm.start\_servers = 2  
pm.min\_spare\_servers = 1  
pm.max\_spare\_servers = 3  
chroot = /var/www/foo/  
chdir = /web/  
[…]

fastcgi\_params:  
[…]  
fastcgi\_connect\_timeout 60;  
fastcgi\_send\_timeout 180;  
fastcgi\_read\_timeout 180;  
fastcgi\_buffer\_size 128k;  
fastcgi\_buffers 4 256k;  
fastcgi\_busy\_buffers\_size 256k;  
fastcgi\_temp\_file\_write\_size 256k;  
fastcgi\_intercept\_errors on;  
[…]

I installed a fresh Wordpress without any plugins on the page and  
tried ApacheBench with -n 1000 -c 10 on it:

Time taken for tests: 25.860 seconds  
Complete requests: 1000  
Failed requests: 875  
(Connect: 0, Receive: 0, Length: 875, Exceptions: 0)

The same page on a standard apache setup spawns 10x php5-cgi:

Time taken for tests: 104.929 seconds  
Complete requests: 1000  
Failed requests: 0

Not sure what’s wrong ☹

Thanks

Dieter

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [November 17, 2011, 6:47pm UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/2 "2011-11-17T18:47:27Z")

</div>

How about the logs file?

Regards,  
Joe

On Thu, Nov 17, 2011 at 11:50 PM, Dieter K.

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [November 17, 2011, 6:54pm UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/3 "2011-11-17T18:54:52Z")

</div>

2011/11/17 Dieter K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Configs:  
> php5-fpm:  
> […]  
> listen = ‘/tmp/foo.socket’  
> user = foo  
> group = foo  
> pm = dynamic

can you test by setting pm = static and pm.max\_children to something a  
little bit hight than 10 (12 or 15).  
Just to ensure the problem does not come from the dynamic PM.

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [November 17, 2011, 11:02pm UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/4 "2011-11-17T23:02:51Z")

</div>

2011/11/17 Jrme L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> can you test by setting pm = static and pm.max\_children to something a  
> little bit hight than 10 (12 or 15).  
> Just to ensure the problem does not come from the dynamic PM.

Sure. I just tested it with 20 children:  
Time taken for tests: 24.580 seconds  
Complete requests: 1000  
Failed requests: 859  
(Connect: 0, Receive: 0, Length: 859, Exceptions: 0)

The same result ☹

This sould be far better with 20 php daemons, it must be another  
problem, like a timeout or something like that?

Thanks

Dieter

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [November 17, 2011, 10:59pm UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/5 "2011-11-17T22:59:47Z")

</div>

2011/11/17 Joe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How about the logs file?

I tried a new benchmark with the old settings:  
Time taken for tests: 24.939 seconds  
Complete requests: 1000  
Failed requests: 861  
(Connect: 0, Receive: 0, Length: 861, Exceptions: 0)

In the logfile from php5-fpm i see 1000 requests (everyone with status  
200):  
[…]

- 
  - 17/Nov/2011:21:55:40 +0000GET /index.php200 /www/index.php  
174.837 20224 102.96%

- 
  - 17/Nov/2011:21:55:40 +0000GET /index.php200 /www/index.php  
175.963 20224 96.61%

- 
  - 17/Nov/2011:21:55:40 +0000GET /index.php200 /www/index.php  
191.407 20224 83.59%

- 
  - 17/Nov/2011:21:55:40 +0000GET /index.php200 /www/index.php  
212.139 20224 75.42%  
[…]

In the nginx-access.log the same:  
[…]  
46.252.24.80 - - [17/Nov/2011:22:55:37 +0100] “GET / HTTP/1.0” 200  
5935 “-” “ApacheBench/2.3”  
46.252.24.80 - - [17/Nov/2011:22:55:37 +0100] “GET / HTTP/1.0” 200  
5931 “-” “ApacheBench/2.3”  
46.252.24.80 - - [17/Nov/2011:22:55:37 +0100] “GET / HTTP/1.0” 200  
5933 “-” “ApacheBench/2.3”  
46.252.24.80 - - [17/Nov/2011:22:55:37 +0100] “GET / HTTP/1.0” 200  
5931 “-” “ApacheBench/2.3”  
[…]

Thanks

Dieter

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [November 18, 2011, 4:14am UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/6 "2011-11-18T04:14:29Z")

</div>

On Fri, Nov 18, 2011 at 5:02 AM, Dieter K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The same result ☹
> 
> This sould be far better with 20 php daemons, it must be another  
> problem, like a timeout or something like that?

Here’s my result on my own site:

[root@eustia ~]# ab -c 10 -n 1000 [http://animebsd.net/](http://animebsd.net/)  
This is ApacheBench, Version 2.3 \<$Revision: 655654 $\>  
Copyright 1996 Adam Twiss, Zeus Technology Ltd, [http://www.zeustech.net/](http://www.zeustech.net/)  
Licensed to The Apache Software Foundation, [http://www.apache.org/](http://www.apache.org/)

Benchmarking [animebsd.net](http://animebsd.net) (be patient)  
Completed 100 requests  
Completed 200 requests  
Completed 300 requests  
Completed 400 requests  
Completed 500 requests  
Completed 600 requests  
Completed 700 requests  
Completed 800 requests  
Completed 900 requests  
Completed 1000 requests  
Finished 1000 requests

Server Software: nginx/1.1.8  
Server Hostname: [animebsd.net](http://animebsd.net)  
Server Port: 80

Document Path: /  
Document Length: 54635 bytes

Concurrency Level: 10  
Time taken for tests: 261.211 seconds  
Complete requests: 1000  
Failed requests: 0  
Write errors: 0  
Total transferred: 54893000 bytes  
HTML transferred: 54635000 bytes  
Requests per second: 3.83 [#/sec] (mean)  
Time per request: 2612.112 [ms] (mean)  
Time per request: 261.211 [ms] (mean, across all concurrent  
requests)  
Transfer rate: 205.22 [Kbytes/sec] received

Connection Times (ms)  
min mean[+/-sd] median max  
Connect: 54 61 134.0 54 3053  
Processing: 1260 2545 304.0 2515 3884  
Waiting: 456 1534 219.6 1510 2673  
Total: 1315 2606 328.8 2570 5409

Percentage of the requests served within a certain time (ms)  
50% 2570  
66% 2605  
75% 2652  
80% 2690  
90% 2978  
95% 3187  
98% 3270  
99% 3902  
100% 5409 (longest request)

Not exactly fast (cpu constrained - kvm instance of 1 core/thread  
e3-1270 cpu, 512MB ram, debian linux 6) but certainly completed all  
requests without fail. 15 php5-cgi instances ran through supervisord  
in tcp mode. There are quite a bit plugins installed, too (but no  
wp-cache of some kind).

No tweaking at nginx side, some timeout and limit increase on php side.

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![komi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@komi](https://www.ruby-forum.com/u/komi)\
**Post date:** [November 18, 2011, 8:33am UTC](https://www.ruby-forum.com/t/bad-perfomance-with-nginx-and-php-fpm/213972/7 "2011-11-18T08:33:50Z")

</div>

2011/11/17 Dieter K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> The same result ☹
> 
> This sould be far better with 20 php daemons, it must be another  
> problem, like a timeout or something like that?

what page are you requesting ?

Start by requesting a very simple PHP page (\<?php echo "toto; ?\>).  
It’s a good start to figure out what’s going on.

Here is what I have with a very short and simple page (20 static  
children on FPM PHP 5.3 trunk and nginx 1.1.4)

fat@dev:~/web$ ab -c 10 -n 1000 [http://xxxxxxxxxx/pwd.php](http://xxxxxxxxxx/pwd.php)  
Server Software: nginx/1.1.4  
Server Hostname: xxxxxx  
Server Port: 80

Document Path: /pwd.php  
Document Length: 22 bytes

Concurrency Level: 10  
Time taken for tests: 0.649 seconds  
Complete requests: 1000  
Failed requests: 0  
Write errors: 0  
Total transferred: 175000 bytes  
HTML transferred: 22000 bytes  
Requests per second: 1539.96 [#/sec] (mean)  
Time per request: 6.494 [ms] (mean)  
Time per request: 0.649 [ms] (mean, across all concurrent  
requests)  
Transfer rate: 263.18 [Kbytes/sec] received

Connection Times (ms)  
min mean[+/-sd] median max  
Connect: 0 0 0.4 0 5  
Processing: 0 6 2.6 6 37  
Waiting: 0 6 2.6 6 37  
Total: 1 6 2.9 6 42

Percentage of the requests served within a certain time (ms)  
50% 6  
66% 6  
75% 7  
80% 7  
90% 7  
95% 7  
98% 12  
99% 19  
100% 42 (longest request)

Then increase the size the PHP page returns (ex: 64k → \<?php echo str\_pad("", 1024\*64, "x"); ?\>)

fat@dev:~/web$ ab -c 10 -n 1000 [http://xxxxxxx/size.php](http://xxxxxxx/size.php)  
Server Software: nginx/1.1.4  
Server Hostname: xxxxxxx  
Server Port: 80

Document Path: /size.php  
Document Length: 65536 bytes

Concurrency Level: 10  
Time taken for tests: 1.242 seconds  
Complete requests: 1000  
Failed requests: 0  
Write errors: 0  
Total transferred: 65689000 bytes  
HTML transferred: 65536000 bytes  
Requests per second: 805.17 [#/sec] (mean)  
Time per request: 12.420 [ms] (mean)  
Time per request: 1.242 [ms] (mean, across all concurrent  
requests)  
Transfer rate: 51651.05 [Kbytes/sec] received

Connection Times (ms)  
min mean[+/-sd] median max  
Connect: 0 0 0.4 0 5  
Processing: 1 12 2.9 12 34  
Waiting: 1 12 2.9 12 32  
Total: 1 12 3.0 12 37

Percentage of the requests served within a certain time (ms)  
50% 12  
66% 13  
75% 14  
80% 14  
90% 16  
95% 17  
98% 18  
99% 20  
100% 37 (longest request)

Then increase the complexity (size, CPU, memory, fork, database  
requests, …)
