Bad perfomance with nginx and php-fpm

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 :frowning:

Thanks

Dieter

How about the logs file?

Regards,
Joe

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

2011/11/17 Dieter K. [email protected]

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.

2011/11/17 Jrme L. [email protected]:

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 :frowning:

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

Thanks

Dieter

2011/11/17 Joe [email protected]:

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

On Fri, Nov 18, 2011 at 5:02 AM, Dieter K.
[email protected] wrote:

The same result :frowning:

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:

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

Benchmarking 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
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

2011/11/17 Dieter K. [email protected]:

The same result :frowning:

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)

[email protected]:~/web$ ab -c 10 -n 1000 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”); ?>)

[email protected]:~/web$ ab -c 10 -n 1000 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, …)