Ab stands for The ApacheBench command. Ab is apache’s built-in stress test tool. Ab is very useful, it can not only apache server web site access stress test, or other types of server stress test. Such as Nginx, Tomcat, IIS, etc.

Principle of ab: The ab command creates multiple concurrent access threads to simulate multiple visitors accessing a URL at the same time. Its test target is URL-based, so it can be used to test the load stress of Apache as well as nginx, Lighthttp, Tomcat, IIS and other Web servers.

The ab command is very light on the machine that is issuing the load, and it doesn’t take up much CPU or memory. However, it will cause a huge load on the target server, similar to the principle of CC attack. Use your own tests also need to be careful, otherwise too much load at once. The target server may run out of resources or even crash.

Install ab command

> yum -y install httpd-tools
Copy the code

The command format

ab [options] [http[s]://]hostname[:port]/path

The command parameteroptions

  • -a auth-username:password Provides BASIC authentication trust for the server. The username and password are separated by a: and sent base64 encoded. This string is sent whether or not the server needs it (that is, whether or not the 401 authentication requirement code was sent).

  • -c concurrency Number of concurrency requests. The default is one at a time.

  • -c cookie-name=value Appends a cookie: line to the request. This typically takes the form of a pair of arguments to name=value. This parameter can be repeated.

  • -d Displays the message “Percentage served within XX [ms] table” (supported for earlier versions).

  • -e csv-file Generates a comma-separated (CSV) file containing the corresponding percentage (in subtlety) of the time required to process each corresponding percentage of requests (from 1% to 100%). Since this format is “binary”, it is more useful than the ‘gnuplot’ format.

  • -g gnuplot-file Writes all test results to a ‘gnuplot’ or TSV (tab-separated) file. This file can be easily imported into Gnuplot, IDL, Mathematica, Igor or even Excel. The first of these is the action title.

  • -h Displays the usage method.

  • -h custom-header Appends additional header information to the request. This parameter typically takes the form of a valid header line containing colon-separated pairs of fields and values (for example, “accept-encoding: zip/zop; 8bit”).

  • -i Performs HEAD requests instead of GET.

  • -k Enables the HTTP KeepAlive function. That is, multiple requests are executed in one HTTP session. By default, KeepAlive is disabled.

  • -n requests Number of requests executed in the test session. By default, only one request is executed, but usually the result is not representative.

  • -p post-file Indicates the file containing the data to be posted.

  • -p proxy-auth-username:password Provides BASIC authentication trust for a proxy. The username and password are separated by a: and sent base64 encoded. This string is sent whether or not the server needs it (that is, whether or not the 401 authentication requirement code was sent).

  • -q If the number of requests processed is greater than 150, ab prints a progress count in stderr for every approximately 10% or 100 requests processed. This -q flag can suppress this information.

  • -s is used when compiling (ab-h displays the information) using SSL protected HTTPS instead of HTTP. This feature is experimental and rudimentary. It’s best not to use it.

  • -s does not display median and standard deviation values, and does not display warning or error messages when the mean and median values are 1 or 2 times the standard deviation values. By default, values such as minimum, mean, and maximum are displayed. (Provides support for previous versions).

  • -t timelimit The maximum number of seconds that the test takes. Its internal implied value is -n 50000. It allows testing of the server to be limited to a fixed total time. By default, there is no time limit.

  • -t Content-type Specifies the content-type header used by POST data.

  • -v Verbosity Sets the detail level of the displayed information. – the value 4 or higher will display header information, the value 3 or higher can display response codes (404, 200, etc.), and the value 2 or higher can display warnings and other information.

  • -v Displays the version number and exits.

  • -w Displays the result in AN HTML table. By default, it is a two-column width table on a white background.

  • -x

    -attributes Sets the string for the
    attribute. This property is filled in
    .
  • -x proxy[:port] Uses a proxy server for requests.

  • -y – Attributes Sets the string for the attribute.

  • -z < TD >-attributes Sets the string for the < TD > attribute.

rightjson.imStress test 1000 requests with 10 concurrent users

> ab -n 1000 -c 10 https://json.im
Copy the code
  • -n 1000 Indicates that the number of requests is 1000
  • -c 10 Indicates that the number of concurrent users is 10

Ab Detailed description of the message returned from the pressure test

Document Path: Apache # Server Hostname: json. Im # Server Port: 80 # Document Path: / # Concurrency Level: 10 # Concurrency Level Time taken for tests: 27.300 seconds # Total access time Complete requests: 1000 # Failed requests: 0 # Write Errors: 0 Total extension: 41054242 bytes # HTML transferred: 40888000 bytes # HTML page actual total number of bytes per second: [#/ SEC] (mean) # number of requests per second [ms] (mean) # number of requests per second 27.300 [ms] (mean, across all concurrent requests) # 1468.58 [Kbytes/ SEC] received # Connection Times (ms) min Mean [+/-sd] Median Max Connect: 43 47 2.4 47 53 Processing: 189 224 40.7 215 895 Waiting: 102 128 38.6 118 794 Total: 233 270 41.3 263 945 Percentage of the requests served within a certain time (ms) 50% 263 #50% User requests returned 66% within 263ms 271 75% return in 271ms #75% return in 279ms 285 #90% return in 285ms #90% return in 303ms 95% 320 # 95% user requests within 320 ms returned 98% 98% of the 341 # user requests within 341 ms returned 99% 99% of the 373 # user requests within 373 ms back to 100% by 945 (the longest request)Copy the code

The login problem

For login problems that are often used in real scenarios, if the interface needs to validate cookies, use -c to write the Cookie contents

> ab-n 100 -c key = value https://json.imCopy the code

Or use -h to customize multiple fields with cookies

> ab -n 100 -H "Cookie: Key1=Value1; Key2=Value2" http://localhost
Copy the code

Tests that interface Header passes the token

> ab -n 1000 -c 10 -H 'token:abc' https://json.im
Copy the code

Original link :rumenz.com/rumenbiji/l… Wechat official account: entry station