I have been starting to work with ab – included with Apache and not a new tool. ab allows for performance testing of web pages, sites and even dynamic scripts based on user load.
我已经开始使用ab – Apache随附的ab,而不是新工具。 ab允许根据用户负载对网页,站点甚至动态脚本进行性能测试。
ab enables the creation of single or multiple requests per second and provides a nice results report.
ab可以每秒创建一个或多个请求,并提供不错的结果报告。
Some of the key options, which can be viewed by running ‘man ab’ on any Linux or OS X installation with Apache installed.
一些关键选项可以通过在安装了Apache的任何Linux或OS X安装上运行“ man ab”来查看。
Options:
选项:
-k: This enables HTTP KeepAlive so that multiple requests are carried out wihtin one session.
-k:这将启用HTTP KeepAlive,以便在一个会话中执行多个请求。
-n: Number of requests to perform, as in 150. They will be issued one after another until done.
-n:要执行的请求数,如150。它们将一个接一个地发出直到完成。
-t: Issues a time limit on the time frame wihtin which the requests can be carried out.
-t:在可以执行请求的时间范围内发出时间限制。
-c: Allows for multiple requests simultaneously rather than one at a time. This can be good to test script performance.
-c:允许同时(而不是一次)多个请求。 这可以很好地测试脚本性能。
-A username and password separated by a colon: This is used to send authentication if login is required on the site you are testing.
-用冒号分隔的用户名和密码:如果要在测试站点上要求登录,则用于发送身份验证。
There are several other options including working through proxy servers, adding headers and cookies.
还有其他几个选项,包括遍历代理服务器,添加标头和cookie。
Results are output to the command line (example below from an OS X localhost Apache install):
结果输出到命令行(以下示例来自OS X localhost Apache安装):
This is ApacheBench, Version 1.3d apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/$revision:>
This is ApacheBench, Version 1.3d apache-1.3 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/$revision:>
Benchmarking localhost (be patient).....done Server Software: Apache/1.3.33 Server Hostname: localhost Server Port: 80
对本地主机进行基准测试(请耐心等待).....完成服务器软件:Apache / 1.3.33服务器主机名:localhost服务器端口:80
Document Path: / Document Length: 1456 bytes
文件路径:/文件长度:1456个位元组
Concurrency Level: 1 Time taken for tests: 1.103 seconds Complete requests: 50 Failed requests: 0 Broken pipe errors: 0 Total transferred: 93500 bytes HTML transferred: 72800 bytes Requests per second: 45.33 [#/sec] (mean) Time per request: 22.06 [ms] (mean) Time per request: 22.06 [ms] (mean, across all concurrent requests) Transfer rate: 84.77 [Kbytes/sec] received
并发级别:1测试时间:1.103秒完整请求:50失败请求:0管道断开错误:0传输总数:93500字节HTML传输:72800字节每秒请求数:45.33 [#/ sec](平均)每请求时间:22.06 [ms](平均)每个请求的时间:22.06 [ms](所有并发请求的平均)传输速率:84.77 [Kbytes / sec]
Connnection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 12 21 60.0 12 438 Waiting: 12 21 59.8 12 436 Total: 12 21 60.4 12 441
连接时间(ms)最小值平均值[+/- sd]最大值最大值连接:0 0 0.3 0 3处理:12 21 60.0 12 438等待:12 21 59.8 12 436总计:12 21 60.4 12 441
Percentage of the requests served within a certain time (ms) 50% 12 66% 13 75% 13 80% 13 90% 14 95% 17 98% 441 99% 441 100% 441 (last request)
在一定时间内服务的请求百分比(ms)50%12 66%13 75%13 80%13 90%14 95%17 98%441 99%441 100%441(最后一个请求)
You can also output the results to a CSV file using a ‘-e filename’ option. ‘-w’ outputs the results to an HTML table. There is the ability to leverage ab from within PHP so as to generate load tests from a web browser and return results, though I have not attempted this as of yet. Primarily I have been running ab on development servers prior to a shift to production — and then running it again in the production environment prior to release.
您也可以使用“ -e文件名”选项将结果输出到CSV文件。 '-w'将结果输出到HTML表。 可以利用PHP内部的ab来从Web浏览器生成负载测试并返回结果,尽管到目前为止我还没有尝试过。 最初,在移交给生产之前,我一直在开发服务器上运行ab-然后在发布之前在生产环境中再次运行它。