Perform a simple stress test on the Apache server using the Apache ab tool
- 2020-05-15 02:44:50
- OfStack
1. Install command ab
sudo apt-get install apache2-utils
2.ab command parameter description
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
// Total number of requests
-n requests Number of requests to perform
//1 Number of simultaneous concurrent requests Total number of requests (n)= The number of *1 A number of concurrent (c)
-c concurrency Number of multiple requests to make
-n requests Number of requests to perform
// the number of requests executed in the test session (the total number of pages to be accessed for this test). By default, only one request is executed.
-c concurrency Number of multiple requests to make
// the number of requests (concurrency) generated one time. The default is 1 at a time.
-t timelimit Seconds to max. wait for responses
// the maximum number of seconds the test was performed. Its internal implicit value is -n 50000. It can limit the testing of the server to a fixed total time. By default, there is no time limit.
-p postfile File containing data to POST
// a file containing data that requires POST in the form "p1=1&p2=2". Use -p 111.txt. (match -T)
-T content-type Content-type header for POSTing
// Content-type header information used by POST data, such as -T "application/ x-www-form-urlencoded". (coordination -p)
-v verbosity How much troubleshooting info to print
// set the level of detail to display information. A value of 4 or more will display header information, a value of 3 or more will display response codes (404, 200, etc.), and a value of 2 or more will display warnings and other information. -V displays the version number and exits.
-w Print out results in HTML tables
// output the results in table HTML format. By default, it is a table with the width of two columns on a white background.
-i Use HEAD instead of GET
// execute the HEAD request 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. -C "c1=1234,c2=2,c3=3" (repeatable)
// -C cookie-name =value attach 1 Cookie: line to the request. The typical form is the 1 parameter pair of name=value. This parameter can be repeated, separated by a comma.
Tip: you can use the session implementation principle to pass JSESSIONID parameters to maintain the session, such as
- C "c1 = 1234, c2 = 2, c3 = 3, JSESSIONID = FF056CD16DA9D71CB131C1D56F0319F8".
-- H attribute header line, eg. 'Accept-Encoding: gzip Inserted 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.
//-P proxy-auth-username :password provides BASIC certification trust to one transit agent. The username and password are separated by one: and sent in base64 code. This string is sent regardless of whether the server needs it (that is, whether the 401 authentication requirement code is sent).
-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.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
// -attributes set property string. There are various statically declared fixed-length buffers in the defect program. In addition, parsing command-line arguments, the server's response headers, and other external inputs is simple, which can have undesirable consequences. It does not fully implement HTTP/ 1.x; Only certain 'expected' response formats are accepted. Frequent use of strstr(3) may cause performance problems, meaning you may be testing ab rather than the performance of the server.
3. Run
ab -n 100 -c 10 //www.ofstack.com/
On / / www. ofstack. com requests for 100 times / 10 concurrent requests stress test results.
Server Software: lighttpd/1.4.20
Server Hostname: www.ofstack.com
Server Port: 80
Document Path: /
Document Length: 2095 bytes
Concurrency Level: 10
// The duration of the entire test
Time taken for tests: 3.303 seconds
// The number of requests completed
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 235200 bytes
HTML transferred: 209500 bytes
// Average processing per second 30 A request
Requests per second: 30.27 [#/sec] (mean)
// The average processing time per request is 330 ms note : There will be 1 time 10 Two concurrent requests 1 A whole
Time per request: 330.335 [ms] (mean)
// The average concurrent request is processed time for 33 ms
Time per request: 33.034 [ms] (mean, across all concurrent requests)
Transfer rate: 69.53 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 51 170 35.9 178 230
Processing: 60 153 64.5 121 263
Waiting: 55 148 64.4 115 258
Total: 235 322 59.9 299 437
Percentage of the requests served within a certain time (ms)
// In this 100 There are 50% in 299 In milliseconds
50% 299
// In this 100 There are 66% in 312 In milliseconds
66% 312
75% 383
80% 412
90% 431
95% 432
98% 436
99% 437
100% 437 (longest request)
PS: how do I view the current number of connections to Apache
Looked at the number of connections and the current number of connections
netstat -ant | grep $ip:80 | wc -l
netstat -ant | grep $ip:80 | grep EST | wc -l
View the number of visits to IP
netstat -nat|grep ":80"|awk '{print $5}' |awk -F: '{print $1}' | sort| uniq -c|sort -n
Linux command:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
watch "netstat -n | awk '/^tcp/ {++S[\$NF]} END {for(a in S) print a, S[a]}'"
Sample results returned:
LAST_ACK 5
SYN_RECV 30
ESTABLISHED 1597
FIN_WAIT1 51
FIN_WAIT2 504
TIME_WAIT 1057
Description:
SYN_RECV represents the number of requests waiting to be processed;
ESTABLISHED represents the normal data transmission state;
TIME_WAIT represents the number of requests waiting for the end of the timeout after processing;
FIN_WAIT1 means that the server end actively requests to close the tcp connection;
FIN_WAIT2 means the client terminates the connection;
LAST_ACK closed 1 TCP connection closed from both directions respectively, the two sides are closed by a single direction data by sending FIN, when both sides of communication to send the last one FIN, sender LAST_ACK at this point, when the sender receives confirmation (Fin Ack confirmation) after shutting down the complete real TCP connection;