Forum: NGINX php5-cgi+Nginx: which is faster 127.0.0.1:9000 or Unix sockets?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ff37ff41246d3dae1eea0cd63dfae180?d=identicon&s=25 Mark Alan (Guest)
on 2008-11-06 15:19
(Received via mailing list)
We intended to test server performance using either:
  /usr/bin/php-cgi -q -b 127.0.0.1:9000  # i.e., the classic IP:port
or:
  /usr/bin/php-cgi -q -b /tmp/php-fastcgi.socket  # i.e. using Unix
domain sockets (and having taken care to change the relevant lines in
nginx config files from: fastcgi_pass 127.0.0.1:9000 to fastcgi_pass
unix:/tmp/php-fastcgi.socket)

In order to verify the impact of the differences described at:
<http://lists.freebsd.org/pipermail/freebsd-perform...

*Material*
- Ubuntu 8.04.1 LTS server
- Nginx 0.6.32 installed with:
   wget
http://http.us.debian.org/debian/pool/main/n/nginx...
   sudo gdebi nginx_0.6.32-3_i386.deb
- PH5 5.2.4 installed with:
   sudo aptitude -R install php5-cli php5-cgi php5-mysql php5-imap
- Apache Bench 2.0.40-dev installed with:
   sudo aptitude -R install apache2-utils

*Methods*
- Create php test script with:
echo -e '<?php\n;\n?>' | sudo -u www-data tee
/var/www/nginx-default/benchtest.php
- Start php-cgi using the Ubuntu's UPSTART script posted as "20081106 -
How to enable Nginx to serve PHP code/pages in UBUNTU" in this Nginx
mailing list.
- Start Apache Bench script with:
   sudo ab -n 10000 -c 100 http://127.0.0.1/benchtest.php | tee
bench-ip.log # after configuring php-cgi to listen at 127.0.0.1:9000
   sudo ab -n 10000 -c 100 http://127.0.0.1/benchtest.php | tee
bench-socket.log #after configuring php-cgi a unix socket at
/tmp/php-fastcgi.socket

*Results and Discussion*
We made a delta file (bench-diff.txt) using the linux diff utility to
show the differences between the two approaches:
- diff -Naur bench-ip.log bench-socket.log > bench-diff.txt

Using the described testing procedure shows that using using Unix domain
sockets, besides the elsewhere described advantage of being  more secure
(see external link above), significantly improves server cgi
performance.


Regards,

M.


File bench-diff.txt follows:
--- cut here ---
--- bench-ip.log  2008-11-06 13:22:30.000000000 +0000
+++ bench-socket.log  2008-11-06 13:18:15.000000000 +0000
@@ -13,31 +13,31 @@
  Document Length:        0 bytes

  Concurrency Level:      100
-Time taken for tests:   5.708770 seconds
+Time taken for tests:   4.980691 seconds
  Complete requests:      10000
  Failed requests:        0
  Write errors:           0
  Total transferred:      1510000 bytes
  HTML transferred:       0 bytes
-Requests per second:    1751.69 [#/sec] (mean)
-Time per request:       57.088 [ms] (mean)
-Time per request:       0.571 [ms] (mean, across all concurrent
requests)
-Transfer rate:          258.20 [Kbytes/sec] received
+Requests per second:    2007.75 [#/sec] (mean)
+Time per request:       49.807 [ms] (mean)
+Time per request:       0.498 [ms] (mean, across all concurrent
requests)
+Transfer rate:          295.94 [Kbytes/sec] received

  Connection Times (ms)
                min  mean[+/-sd] median   max
-Connect:        0    0   1.4      0      27
-Processing:     9   55   9.5     55     156
-Waiting:        9   55   9.3     55     154
-Total:         15   56   9.0     55     156
+Connect:        0    1   4.1      0      35
+Processing:     4   47  12.8     48     145
+Waiting:        4   46  12.6     48     129
+Total:         12   48  11.1     49     145

  Percentage of the requests served within a certain time (ms)
-  50%     55
-  66%     57
-  75%     59
-  80%     61
-  90%     67
-  95%     71
-  98%     81
-  99%     91
- 100%    156 (longest request)
+  50%     49
+  66%     51
+  75%     53
+  80%     55
+  90%     60
+  95%     69
+  98%     78
+  99%     83
+ 100%    145 (longest request)
--- cut here ---
1d0f015a959f3ad34941a5f58f72b932?d=identicon&s=25 Volodymyr Kostyrko (Guest)
on 2008-11-06 15:37
(Received via mailing list)
Mark Alan wrote:

> echo -e '<?php\n;\n?>' | sudo -u www-data tee
> /var/www/nginx-default/benchtest.php

You are testing here only one aspect - connection rate. Try something
like phpinfo() or just some huge html file with php extension - this way
php would do nothing apart feeding the data to nginx through socket. It
would be good to see tests for 50k docs and for something like 500k.
B06eeb3c664683b78f1bd62a80cd8ca4?d=identicon&s=25 Roxis (Guest)
on 2008-11-06 15:37
(Received via mailing list)
funny, but

ab -k would be mutch better
02a35d31be48f389d76abfbb8b39191f?d=identicon&s=25 Joe Aston (Guest)
on 2008-11-08 02:35
(Received via mailing list)
Thanks for sharing - this is very interesting.

How did you create the socket for fastcgi?
559ec3a67330138cb0e3e6e318fc3ee0?d=identicon&s=25 Michael Schmarck (Guest)
on 2008-11-08 07:20
(Received via mailing list)
Hi.

2008/11/8 Joe Aston <joe@joeaston.com>:
> Thanks for sharing - this is very interesting.
>
> How did you create the socket for fastcgi?

It's created automatically by PHP. Nothing needs to be
done from the user, as far as that's concerned.

Michael
Ff37ff41246d3dae1eea0cd63dfae180?d=identicon&s=25 Mark Alan (Guest)
on 2008-11-08 09:47
(Received via mailing list)
Joe Aston wrote:
> How did you create the socket for fastcgi?

Check my posts (with subject starting with "20081106 -") to see the
HowTo's


M.
This topic is locked and can not be replied to.