Speed bottleneck of the web server

非常典型的多层架构:
第一层 Nginx
第二层 php fastcgi
第三层 memcached
第四层 MySql

Apache 有个 mod_php,相当于合并了第一层和第二层,Nginx 没有 module for php,这不是什么问题,分层更利于扩展。第三层的加入完全是为了减轻数据库压力,提高性能。目前第2,3,4层之间的优化差不多到极限了(或者说到我能力的极限了),但第1,2层之间尚有潜力可挖。

not_in_use.php 和 not_in_use.html 都是一个静态文件,没有数据库操作。但 php 文件必须由 Nginx 经由 php fastcgi (使用 unix socket)产生,html 则由 Nginx 直接访问文件系统,就单因素分析,php fastcgi 是普通文件系统速度的34%,所以要想办法绕开 php fastcgi。以下测试在数据中心主机上直接运行 ApacheBench。

测试一:
$ ab -kc 100 -n 500 http://magento/not_in_use.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking magento (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 500 requests

Server Software: nginx/0.6.36
Server Hostname: magento
Server Port: 80

Document Path: /not_in_use.php
Document Length: 7686 bytes

Concurrency Level: 100
Time taken for tests: 0.336355 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Keep-Alive requests: 0
Total transferred: 4089329 bytes
HTML transferred: 4004406 bytes
Requests per second: 1486.52 [#/sec] (mean)
Time per request: 67.271 [ms] (mean)
Time per request: 0.673 [ms] (mean, across all concurrent requests)
Transfer rate: 11871.39 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 11 17.8 3 58
Processing: 13 49 17.9 50 94
Waiting: 3 45 18.8 46 88
Total: 25 60 14.2 61 94

Percentage of the requests served within a certain time (ms)
50% 61
66% 70
75% 72
80% 74
90% 79
95% 80
98% 84
99% 86
100% 94 (longest request)

=======================================================
测试二:
$ ab -kc 100 -n 500 http://magento/not_in_use.html
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking magento (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 500 requests

Server Software: nginx/0.6.36
Server Hostname: magento
Server Port: 80

Document Path: /not_in_use.html
Document Length: 7686 bytes

Concurrency Level: 100
Time taken for tests: 0.115725 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Keep-Alive requests: 500
Total transferred: 3959000 bytes
HTML transferred: 3843000 bytes
Requests per second: 4320.59 [#/sec] (mean)
Time per request: 23.145 [ms] (mean)
Time per request: 0.231 [ms] (mean, across all concurrent requests)
Transfer rate: 33406.78 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 7.3 0 22
Processing: 7 17 4.1 18 23
Waiting: 7 16 4.0 17 23
Total: 7 20 9.9 18 41

Percentage of the requests served within a certain time (ms)
50% 18
66% 20
75% 22
80% 37
90% 39
95% 40
98% 41
99% 41
100% 41 (longest request)

Leave a comment

Your email address will not be published. Required fields are marked *