Test performance with AB

Source: Internet
Author: User

AB is a performance testing tool provided by the Apache server. It can simulate access to a specified URL and generate a report on access efficiency, we can see the performance of the website under high pressure.

AB .exe in Windows is generally in the bin directory of the Apache installation directory. Here are a few examples I have actually used:

400 requests for http: // localhost/dz7/index. php
ab -n 400 http://localhost/dz7/index.php
After the test is completed, AB will output the test result:

Benchmarking localhost (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsFinished 400 requestsServer Software:        Apache/2.2.11Server Hostname:        localhostServer Port:            80Document Path:          /dz7/index.phpDocument Length:        7015 bytesConcurrency Level:      1Time taken for tests:   21.623 secondsComplete requests:      400Failed requests:        399   (Connect: 0, Receive: 0, Length: 399, Exceptions: 0)Write errors:           0Total transferred:      2968811 bytesHTML transferred:       2805205 bytesRequests per second:    18.50 [#/sec] (mean)Time per request:       54.057 [ms] (mean)Time per request:       54.057 [ms] (mean, across all concurrent requests)Transfer rate:          134.08 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    0   1.3      0      16Processing:    31   54  64.5     47    1265Waiting:       16   51  64.3     47    1250Total:         31   54  64.5     47    1265Percentage of the requests served within a certain time (ms)  50%     47  66%     47  75%     47  80%     47  90%     47  95%     62  98%    141  99%    187 100%   1265 (longest request)

Parameter-N is used to set the number of requests. In addition, you can use-C to set the number of concurrent requests. For example, to simulate 50 concurrent accesses, you can use
ab -n 400 -c 50 http://localhost/dz7/index.php

In addition, there is a practical problem, that is, how to use AB to simulate the access of logged-on users. The login mechanism of most programs is implemented using cookies + sessions. The browser sends a cookie for each request, which records the session Sid. You can use the firebug plug-in of Firefox to determine the content in the cookie.

It can be seen that the login user's content is "qfi_sid = 55yssk ". AB can use-C (uppercase C) to set the cookie sent for each request. So
ab -n 400 -c 50 -C "QfI_sid=55ySsk" http://localhost/dz7/index.php
You can simulate 400 accesses to a logged-on user with a concurrency of 50.

Finally, I will reveal another stunt:
ab --help

 

 

 

 

 

 

 

 

 

 

 

Detailed introduction and usage:

Apachetracing (AB)

ApacheBench can simulate continuous online requests for a specific URL, and simulate online requests with the same number of requests at the same time, therefore, apachetracing can help us simulate the actual launch possible conditions during website development, and use the simulated data as the basis for adjusting server settings or programs.

 

 

Summary

 

AB [-A auth-username] [-C concurrency] [-C cookie-name = value] [-D] [-e CSV-file] [-G gnuplot-file] [-H] [-H custom-header] [-I] [-K] [-N requests] [-P post-file] [-P proxy-auth-username] [-q] [-S] [-S] [-T timelimit] [-T Content-Type] [-V verbosity] [-V] [-W] [-x <Table>-attributes] [-x proxy [] [-Y <tr>-attributes] [-z <TD>-attributes] [http: //] hostname [: Port]/path

 

 

Option

 

-A Auth-UserName: Password

Provides basic authentication trust to the server. The user name and password are separated by one and sent in base64 encoding format. This string is sent regardless of whether the server needs it (that is, whether the 401 authentication request code is sent.

-C concurrency

The number of requests generated at a time. The default value is one at a time.

-C cookie-name = Value

Append a cookie to the request: Row. The typical form is a parameter pair of name = value. This parameter can be repeated.

-D

Messages for "percentage served within XX [MS] Table" are not displayed (supported for previous versions ).

-E csv-File

Generate a comma-separated (CSV) file that contains the time (in a subtle unit) required to process each percentage of requests (from 1% to 100%. This format has been "binary", so it is more useful than the 'gnupload' format.

-G gnuplot-File

Write all test results to a 'gnupload' or TSV (separated by tabs) file. This file can be easily imported to gnuplot, IDL, Mathematica, Igor or even excel. The title of the first behavior.

-H

Display usage.

-H custom-Header

Append additional header information to the request. A typical form of this parameter is a valid header information line, which contains pairs of fields and values separated by colons (for example, "Accept-encoding: Zip/zop; 8bit ").

-I

Execute the head request instead of get.

-K

Enable the HTTP keepalive function, that is, to execute multiple requests in an HTTP session. By default, keepalive is not enabled.

-N requests

The number of requests executed in the test session. By default, only one request is executed, but the result is usually not representative.

-P post-File

The file that contains the data to be post.

-P proxy-auth-UserName: Password

Provides basic authentication trust for a transit proxy. The user name and password are separated by one and sent in base64 encoding format. This string is sent regardless of whether the server needs it (that is, whether the 401 authentication request code is sent.

-Q

If the number of requests processed exceeds 150, AB will output a progress count in stderr every time it processes about 10% or 100 requests. This Q mark can suppress this information.

-S

It is used for compiling (AB-H displays relevant information) using SSL protected HTTPS instead of HTTP. This function is experimental and simple. It is best not to use it.

-S

The mean value and standard deviation value are not displayed, and no warning or error message is displayed when the mean value and the mean value are one to two times the standard deviation value. By default, the minimum, average, maximum, and other values are displayed. (To support previous versions ).

-T timelimit

The maximum number of seconds for testing. The implicit value is-N 50000. It limits the server test to a fixed total time. By default, there is no time limit.

-T Content-Type

The Content-Type Header used by the post data.

-V verbosity

Set the details of the display information-4 or greater. The header information is displayed. 3 or a greater value can display the response code (404,200, etc.). 2 or a greater value can display warnings and other information.

-V

Show the version number and exit.

-W

Output results in HTML table format. By default, it is a table of the width of the two columns of the white background.

-X <Table>-attributes

Set the string of the <Table> attribute. This attribute is filled in <Table here>.

-X proxy [: Port]

Use a proxy server for requests.

-Y <tr>-attributes

Set the string of the <tr> attribute.

-Z <TD>-attributes

Set the string of the <TD> attribute.

 

Defects

The program has various static declared fixed-length buffers. In addition, parsing command line parameters, server response headers, and other external inputs is also simple, which may have adverse consequences.

 

It does not fully implement HTTP/1.x; only accept some 'preview' response formats. Frequent use of strstr (3) may cause performance problems, that is, you may be testing the performance of AB rather than the server.

 

 

Example:

The result is similar to (# for Chinese translation ):

 

Server Software: Apache/2.0.55

Server Hostname: localhost

Server port: 80

 

Document path:/1.php

Document length: 82522 bytes # request document size

 

Concurrency level: 50 # concurrency

Time taken for tests: 92.76140 seconds # Time consumed to complete all requests

Complete requests: 10000 # Number of all requests

Failed requests: 1974 # failed requests

(CONNECT: 0, Length: 1974, exceptions: 0)

Write errors: 0

Total transferred: 827019400 bytes # total transmission size

HTML transferred: 825219400 bytes

Requests per second: 108.61 [#/sec] (mean) # Number of requests per second (average)

Time per request: 460.381 [MS] (mean) # Time of each concurrent request (all concurrency)

Time per request: 9.208 [MS] (mean, average SS all concurrent requests) # Time per request (average concurrency)

Transfer Rate: 8771.39 [Kbytes/sec] transferred ed # transmission rate

 

Connection times (MS) # connection time

Min mean [+/-SD] median Max

Connect (# connection): 0 0 2.1 0 46

Processing (# Processing): 31 458 94.7 438 1078

Waiting (# Waiting): 15 437 87.5 422 938

Total: 31 458 94.7 438

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.