我正在尝试编写一个我试图测量其效率的脚本.我有一些问题:-
对于小型应用程序,是否需要这种分析?还是我变得偏执?(假设大多数代码效率很高/没有无限循环)
反对我应该对此进行基准测试?我应该比较什么?
以下是我从ab获得的效率输出.这样太过分了吗?我是否正朝着设计此应用程序的错误方向前进?我应该注意哪些警告信号?
abs -n10000 -c100 http://localhost/testapp This is ApacheBench, Version 2.3 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking localhost (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.2.10 Server Hostname: localhost Server Port: 80 Document Path: /testapp Document Length: 525 bytes Concurrency Level: 100 Time taken for tests: 33.608 seconds Complete requests: 10000 Failed requests: 5179 (Connect: 0, Receive: 0, Length: 5179, Exceptions: 0) Write errors: 0 Total transferred: 6973890 bytes HTML transferred: 5253890 bytes Requests per second: 297.55 [#/sec] (mean) Time per request: 336.080 [ms] (mean) Time per request: 3.361 [ms] (mean, across all concurrent requests) Transfer rate: 202.64 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 1.5 0 109 Processing: 8 334 403.9 176 3556 Waiting: 7 334 403.9 176 3556 Total: 9 335 403.8 177 3556 Percentage of the requests served within a certain time (ms) 50% 177 66% 296 75% 415 80% 519 90% 842 95% 1141 98% 1615 99% 1966 100% 3556 (longest request)
我正在使用PHP编写脚本.在进一步测试时,我还发现如果我从PHP脚本中注释MySQL连接部分,"失败请求"将变为0.怎么了?如何降低此故障率?
谢谢你,亚力克
您是否期望100个并发请求?您希望在30秒内收到10K请求吗?
您可以运行此基准测试,但要问问自己这意味着什么.考虑一下您将接收的实际流量.你真的需要一个问题来对照:
我希望我的网站有3,000名用户.
我希望在高峰期使用时,其中500个将会点击页面
通常使用的是一分钟内3个请求: 3 * 500 / 60 = ~ 25 req/sec
我的网站可以处理25 req/sec并且响应迅速(每个请求<200ms)吗?
除非您处于网络的前几个百分点,否则您的页面在现实生活中将不会看到100个并发请求.针对该流量级别调整您的网站没有意义.要获得这些数字,您需要在架构级别(数据库使用,缓存方法等)进行设计妥协:因此在数据库启动时您的失败次数.
如果您只是尝试配置脚本,请使用xdebug查找代码花费时间的位置.