测试 apc php
测试php编译缓存apc的效果。
使用ab测试的命令是:/ab -n 1000 -c 5 http://localhost/abtest.php
开启apc:
server software: apache/2.2.21server hostname: localhostserver port: 80document path: /abtest.phpdocument length: 662 bytesconcurrency level: 5time taken for tests: 11.464 secondscomplete requests: 1000failed requests: 0write errors: 0total transferred: 879000 byteshtml transferred: 662000 bytesrequests per second: 87.23 [#/sec] (mean)time per request: 57.319 [ms] (mean)time per request: 11.464 [ms] (mean, across all concurrent requests)transfer rate: 74.88 [kbytes/sec] receivedconnection times (ms) min mean[+/-sd] median maxconnect: 0 0 0.4 0 4processing: 25 57 8.5 55 130waiting: 24 56 8.5 55 130total: 25 57 8.5 55 130percentage of the requests served within a certain time (ms) 50% 55 66% 57 75% 58 80% 58 90% 62 95% 68 98% 90 99% 95 100% 130 (longest request)
不开启apc:
server software: apache/2.2.21server hostname: localhostserver port: 80document path: /abtest.phpdocument length: 662 bytesconcurrency level: 5time taken for tests: 29.521 secondscomplete requests: 1000failed requests: 0write errors: 0total transferred: 879000 byteshtml transferred: 662000 bytesrequests per second: 33.87 [#/sec] (mean)time per request: 147.607 [ms] (mean)time per request: 29.521 [ms] (mean, across all concurrent requests)transfer rate: 29.08 [kbytes/sec] receivedconnection times (ms) min mean[+/-sd] median maxconnect: 0 0 0.4 0 2processing: 35 147 10.7 146 242waiting: 35 146 10.7 146 242total: 36 147 10.7 146 242percentage of the requests served within a certain time (ms) 50% 146 66% 147 75% 149 80% 151 90% 155 95% 160 98% 173 99% 180 100% 242 (longest request)
再开启apc:
server software: apache/2.2.21server hostname: localhostserver port: 80document path: /huodongnewtest/abtest.phpdocument length: 662 bytesconcurrency level: 5time taken for tests: 10.361 secondscomplete requests: 1000failed requests: 0write errors: 0total transferred: 879000 byteshtml transferred: 662000 bytesrequests per second: 96.51 [#/sec] (mean)time per request: 51.807 [ms] (mean)time per request: 10.361 [ms] (mean, across all concurrent requests)transfer rate: 82.85 [kbytes/sec] receivedconnection times (ms) min mean[+/-sd] median maxconnect: 0 0 0.5 0 9processing: 26 51 12.8 49 227waiting: 26 51 12.8 49 227total: 26 51 12.8 50 228percentage of the requests served within a certain time (ms) 50% 50 66% 51 75% 52 80% 53 90% 57 95% 60 98% 63 99% 68 100% 228 (longest request)
再关闭apc:
server software: apache/2.2.21server hostname: localhostserver port: 80document path: /huodongnewtest/abtest.phpdocument length: 662 bytesconcurrency level: 5time taken for tests: 28.444 secondscomplete requests: 1000failed requests: 0write errors: 0total transferred: 879000 byteshtml transferred: 662000 bytesrequests per second: 35.16 [#/sec] (mean)time per request: 142.222 [ms] (mean)time per request: 28.444 [ms] (mean, across all concurrent requests)transfer rate: 30.18 [kbytes/sec] receivedconnection times (ms) min mean[+/-sd] median maxconnect: 0 0 0.4 0 2processing: 35 141 8.3 142 174waiting: 34 141 8.3 141 173total: 36 141 8.3 142 175percentage of the requests served within a certain time (ms) 50% 142 66% 144 75% 145 80% 146 90% 151 95% 155 98% 158 99% 162 100% 175 (longest request)
回复讨论(解决方案) 命令改为:/ab -c 5 -n 10 http://localhost/abtest.php
未开启apc:
benchmarking localhost (be patient).....doneserver software: apache/2.2.21server hostname: localhostserver port: 80document path: abtest.phpdocument length: 815 bytesconcurrency level: 5time taken for tests: 18.188 secondscomplete requests: 10failed requests: 0write errors: 0total transferred: 10320 byteshtml transferred: 8150 bytesrequests per second: 0.55 [#/sec] (mean)time per request: 9093.750 [ms] (mean)time per request: 1818.750 [ms] (mean, across all concurrent requests)transfer rate: 0.55 [kbytes/sec] receivedconnection times (ms) min mean[+/-sd] median maxconnect: 0 0 0.5 1 1processing: 9026 9065 48.1 9040 9155waiting: 9026 9065 48.2 9039 9155total: 9026 9066 48.1 9041 9156warning: the median and mean for the initial connection time are not within a normal deviation these results are probably not that reliable.percentage of the requests served within a certain time (ms) 50% 9041 66% 9077 75% 9104 80% 9129 90% 9156 95% 9156 98% 9156 99% 9156 100% 9156 (longest request)
开启apc:
用于测试的文件abtest.php含有类的引入和实例化,无数据库连接。
测试结果:
apc开启和关闭,cpu的占用率都是100%,这意味着处理能力相同。而完成的时间如下:
time taken for tests: 11.464 seconds
time taken for tests: 29.521 seconds
time taken for tests: 10.361 seconds
time taken for tests: 28.444 seconds
很明显,接近3倍。