Benchmark testing tools (ab)
What is ab? ab is a command line-based tool that can run on Windows and Linux platforms. Why choose this tool? Easy to use, just enter a few command options and get results, and easy to install.
Install ab
win: If there is an apache development environment locally, then ab is in the bin directory under the apache directory by default. You can see it by opening the bin directory linux: Just yum install httpd-tools and install it
Easy to get started
Type the following code directly (note to switch the directory where ab is located) -c 10 means the number of concurrency is 10 -n 10 for a total of 100 visits Followed by the URL to be visited, remember to indispensable http://
- D:phpStudyApachebin>ab -c 10 -n 1000 http://example.com/phpinfo.php
Copy the code
Wait for ab to run it yourself and get the following results
- #ab tool Description, pay attention to the version number
- This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licenseed to The Apache Software Foundation, http://www.apache.org/
-
- #Test results, a total of 1000 tests, the access progress is displayed every 100 times, the website visited is example.com
- Benchmarking example.com (be patient)
- Completed 100 requests
- Completed 200 requests
- Completed 300 requests
- Completed 400 requests
- Completed 500 requests
- Completed 600 requests
- Completed 700 requests
- Completed 800 requests
- Completed 900 requests
- Completed 1000 requests
- Finished 1000 requests
-
- #Server information
- Server Software: nginx/1.6.2 #Server web software
- Server Hostname: example.com #Host address
- Server Port: 80 #Access port
-
- #Document information
- Document Path: /phpinfo.php #Accessed document
- Document Length: 94804 bytes #Return the number of bytes of the result size (including the total number of bytes of all content in html, js, css, images and responses)
-
- #Link information
- Concurrency Level: 10 #Concurrency number, -c 10 sets 10 concurrencies
- Time taken for tests: 7.498 seconds #Total time taken, unit seconds
- Complete requests: 1000 #The sum of the total number of completed requests in the total requests
- Failed requests: 219 #The sum of the number of failed requests
- (Connect: 0, Receive: 0 , Length: 219, Exceptions: 0)
- Non-2xx responses: 9 #The total number of successful requests in the 2xx series that were not received
- Total transferred: 94135779 bytes #The total size bytes of the total response distance in the entire total number of requests, including header information
- HTML transferred: 93952076 bytes #The total size bytes of the text content in the total number of requests
- Requests per second: 133.36 [#/sec] (mean) #The number of concurrency supported per second, here is 133.36 concurrency supported per second
- Time per request: 74.984 [ms] (mean) #The total time it takes to complete a request
- Time per request: 7.498 [ms] (mean, across all concurrent requests) #The total time it takes to complete one request among all concurrent requests
- Transfer rate : 12259.83 [Kbytes/sec] received #Total number of bytes received per second (KB)
-
- #Test time result data, pay attention to the Total item, in the case of 10 concurrency, the minimum time to complete a request (min ) 9 milliseconds, maximum time consuming (max) 146 milliseconds
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.7 0 20
- Processing: 9 74 22.2 68 146
- Waiting: 6 73 22.1 67 143
- Total: 9 74 22.2 68 146
-
- #Percentage of completed requests, for example, the first item, 50% 68, means that half of the requests are completed within 68 milliseconds, 95% 129, means that out of 1000 requests, 100% Ninety-eight requests were completed in 129 milliseconds
- Percentage of the requests served within a certain time (ms)
- 50% 68
- 66% 78
- 75% 86
- 80% 92
- 90% 109
- 95% 122
- 98% 129
- 99% 133
- 100% 146 (longest request)
Copy code
ab option
Enter the following command to get the ab help document, which explains the usage and the meaning of command options respectively
- D:phpStudyApachebin>ab -h
Copy the code
ab帮助文档的输出
- Usage: ab [options] [http://]hostname[:port]/path
- Options are:
- -n requests Number of requests to perform
- -c concurrency Number of multiple requests to make at a time
- -t timelimit Seconds to max. to spend on benchmarking
- This implies -n 50000
- -s timeout Seconds to max. wait for each response
- Default is 30 seconds
- -b windowsize Size of TCP send/receive buffer, in bytes
- -B address Address to bind to when making outgoing connections
- -p postfile File containing data to POST. Remember also to set -T
- -u putfile File containing data to PUT. Remember also to set -T
- -T content-type Content-type header to use for POST/PUT data, eg.
- 'application/x-www-form-urlencoded'
- Default is 'text/plain'
- -v verbosity How much troubleshooting info to print
- -w Print out results in HTML tables
- -i Use HEAD instead of GET
- -x attributes String to insert as table attributes
- -y attributes String to insert as tr attributes
- -z attributes String to insert as td or th attributes
- -C attribute Add cookie, eg. 'Apache=1234'. (repeatable)
- -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
- Inserted after all normal header lines. (repeatable)
- -A attribute Add Basic WWW Authentication, the attributes
- are a colon separated username and password.
- -P attribute Add Basic Proxy Authentication, the attributes
- are a colon separated username and password.
- -X proxy:port Proxyserver and port number to use
- -V Print version number and exit
- -k Use HTTP KeepAlive feature
- -d Do not show percentiles served table.
- -S Do not show confidence estimators and warnings.
- -q Do not show progress when doing more than 150 requests
- -l Accept variable document length (use this for dynamic pages)
-
- -g filename Output collected data to gnuplot format file.
- -e filename Output CSV file with percentages served
- -r Don't exit on socket receive errors.
- -m method Method name
- -h Display usage information (this message)
复制代码
英文看不懂,附上中文解释,网上抄的,我没试过
- -n 即requests,用于指定压力测试总共的执行次数。
- -c 即concurrency,用于指定压力测试的并发数。
- -t 即timelimit,等待响应的最大时间(单位:秒)。
- -b 即windowsize,TCP发送/接收的缓冲大小(单位:字节)。
- -p 即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。
- -u 即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。
- -T 即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。
- -v 即verbosity,指定打印帮助信息的冗余级别。
- -w 以HTML表格形式打印结果。
- -i 使用HEAD请求代替GET请求。
- -x 插入字符串作为table标签的属性。
- -y 插入字符串作为tr标签的属性。
- -z 插入字符串作为td标签的属性。
- -C 添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)。
- -H 添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。
- -A 添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。
- -P 添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。
- -X 指定使用的代理服务器和端口号,例如:"126.10.10.3:88"。
- -V 打印版本号并退出。
- -k 使用HTTP的KeepAlive特性。
- -k 使用HTTP的KeepAlive特性。
- -d 不显示百分比。
- -S 不显示预估和警告信息。
- -g 输出结果信息到gnuplot格式的文件中。
- -e 输出结果信息到CSV格式的文件中。
- -r 指定接收到错误信息时不退出程序。
- -h 显示用法信息,其实就是ab -help。
复制代码
Generally use -n, -c, -t -n Total number of requests -c Concurrency count -t Concurrency count within specified seconds
Let me talk about the usage of -t. The following means 10 concurrent visits in 20 seconds
- D:phpStudyApachebin> ab -c 10 -t 20 http://example.com/phpinfo.php
- This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache. org/
-
- Benchmarking example.com (be patient)
- Finished 3011 requests
-
-
- Server Software: nginx/1.6.2
- Server Hostname: example.com
- Server Port: 80
-
- Document Path: /phpinfo.php
- Document Length: 94804 bytes
-
- Concurrency Level: 10
- Time taken for tests: 20.006 seconds
- Complete requests: 3011
- Failed requests: 495
- (Connect: 0, Receive: 0, Length: 495, Exceptions: 0)
- Non-2xx responses: 54
- Total transferred: 280896464 bytes
- HTML transferred: 280344222 bytes
- Requests per second: 150.50 [#/sec] (mean)
- Time per request: 66.444 [ms] (mean)
- Time per request: 6.644 [ms] (mean, across all concurrent requests)
- Transfer rate: 13711.44 [Kbytes/sec] received
-
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.5 0 10
- Processing: 6 66 17.6 63 203
- Waiting: 5 64 17.3 61 202
- Total: 6 66 17.6 63 203 % 75
- 90% 82
- 95% 92
- 98% 113
- 99% 125
- 100% 203 (longest request)
-
-
- Copy code
-
-
- Special note: If you visit http://www.example.com/, no specific File, remember to add the last /, be sure to add it! ! ! Otherwise, you may not be able to access it! ! !
Circumstances that may affect benchmark testing
Geolocation and network issues
Response file size
Code complexity
Browser parsing
Web server configuration
Geolocation and network issues
If the web server is stored overseas, then we access the overseas website locally. As you can imagine, we pass through the router nodes, server nodes, and then through the optical cable under the Pacific Ocean, and then access the web server. After processing by the web server , continue with the submarine optical cable, and jump back to each server and routing node. This will definitely affect the test results (my suggestion is to conduct ab testing directly on the server)
Response file size
If a 3MB page is sent, the server network card will split the 3MB data into a single small data packet. During the transmission process, if only one data packet is damaged or lost, all data packets will be resent, so the sent packet The smaller the better, and at the same time, the smaller the data transfer, the faster it is transferred to the user's machine.
code complexity
The complexity of the code means complex processing of business logic, as well as file calls, database access, remote API interface calls, etc., which will affect the processing time
Browser parsing
Each browser has its own way of processing js, css, and html. Just think about the difference between IE8 and below and chrome
Web server settings
After the general Web server is installed, simple settings can be used to implement Web services (out of the box). However, such settings do not maximize the performance of the Web server. Senior engineers are required to configure the server to maximize performance. Here are simple and practical Keep-Alive instructions. The function of Keep-Alive is that the web server opens a specific number of connections and keeps these connections open so that it can quickly process incoming requests, so that it does not open a connection for each incoming request and then process the request. , Reduce the number of processes on the server that process requests, thereby increasing the number of concurrencies. Use -k in ab for testing, such as the following sentence
#-k, which allows the server to save 5 concurrent connections in an open and allowed state, allowing other requests to be processed quickly and reducing the processing time of creating new requests. ab -c 5 -t 100 -k http://www.example.com/
|