ab is the abbreviation of Apache bench command
ab is apache's own stress testing tool. ab is very practical. It can not only test the web site access stress of apache servers, but also stress test other types of servers. For example, nginx, tomcat, haproxy, etc
Principle of ab
Principle of ab: the ab command will create multiple concurrent access threads to simulate multiple visitors accessing a URL at the same time. Its test target is based on URL, so it can be used to test the load pressure of apache as well as the pressure of nginx, lighthttp, tomcat, IIS and other Web servers.
The ab command has a very low requirement on the computer that issues the load. It will neither occupy a high CPU nor a lot of memory. But it will cause huge load to the target server, and its principle is similar to CC attack. You also need to pay attention to your own test use, otherwise there will be too much load at one time. It may cause the target server to run out of resources, or even cause a crash.
Installation of ab
$ yum -y install httpd-tools #Check if the installation is successful $ ab -V This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
Application of ab
Note: there are many command parameters for ab. we often use - c and - n parameters
$ ab -c 10 -n 100 http://test.basofhala.com/ //Note: process 100 requests at the same time and run http://test.basofhala.com 10 times/ #Parameter Description: -c10 Indicates that the number of concurrent users is 10 -n100 Indicates that the total number of requests is 100 #test result $ ab -c 10 -n 100 http://test.basofhala.com/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking test.bassofhala.com (be patient).....done Server Software: nginx #Name of test server Server Hostname: test.basofhala.com #Requested URL host name Server Port: 80 #web server listening port Document Path: / #The root absolute path in the URL of the request. Through the suffix of the file, we can generally understand the type of the request Document Length: 4102 bytes #Body length of HTTP response data Concurrency Level: 10 #Number of concurrent users, which is one of the parameters we set Time taken for tests: 6.361 seconds #The total time taken for all these requests to be processed, in seconds omplete requests: 100 # The total number of requests, which is one of the parameters we set Failed requests: 1 #Indicates the number of failed requests. Here, failure refers to the exception of the request in connection with the server, sending data and other links, as well as the timeout after no response (Connect: 0, Receive: 0, Length: 1, Exceptions: 0) Write errors: 0 Total transferred: 474318 bytes #The sum of the response data lengths for all requests. Include the header information and body data length of each HTTP response data HTML transferred: 412818 bytes #The sum of the body data in the response data of all requests, that is, the length of the header information in the HTTP response data in the Total transferred is subtracted Requests per second: 15.72 [#/sec] (mean) #Throughput, calculation formula: Complete requests/Time taken for tests Time per request: 636.133 [ms] (mean) #Time token for tests / (Complete requests/Concurrency Level). Time spent processing all requests / (total requests / concurrent users) Time per request: 63.613 [ms] (mean, across all concurrent requests) #The average request waiting time of the server is calculated by the formula: time token for tests / complete requests, which is exactly the reciprocal of the throughput. Time per request/Concurrency Level Transfer rate: 72.82 [Kbytes/sec] received #It indicates the length of data obtained from the server in unit time by these requests. The calculation formula is: Total trnasferred/ Time taken for tests. This statistic well shows the demand for export broadband when the processing capacity of the server reaches the limit. Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 1 Processing: 523 569 37.3 561 648 Waiting: 523 569 37.3 561 648 Total: 524 569 37.4 561 649 Percentage of the requests served within a certain time (ms) 50% 561 66% 580 75% 595 80% 620 90% 626 95% 639 98% 647 99% 649 100% 649 (longest request) #Percentage of requests served within a certain time (MS) this part of data is used to describe the distribution of processing time of each request. For example, in the above test, 80% of the request processing time is 620ms. This processing time refers to the previous Time per request, that is, for a single user, the average processing time of each request //Note: the whole test result shows that there are 1 failed requests