Apache-ab Pressure Test Example

Source: Internet
Author: User
Tags connection reset

An AB background introduction

Apache comes with the stress test tool Apache bench--abbreviation AB, which is very easy to use and can completely touch your various conditions to initiate test requests to the Web server. AB can initiate test requests locally directly on the Web server, which is critical to understanding the processing performance of the server, because it does not include the network transfer time of the data and the local computing time of the user's PC .

  abis a tool for benchmarking your Apache hypertext Transfer Protocol (HTTP) server. It is the designed to give a impression of what your current Apache installation performs. This especially shows what many requests per second your Apache installation is capable of serving. -See more At:http://www.rickyzhu.com/129_quick-introduce-to-ab.html#sthash.seo8xgfh.dpuf

The supported parameters and parameters are described below:

AB[ -Aauth-username:password] [ -Cconcurrency] [ -Ccookie-name=value] [ -D] [ -ecsv-file] [ -ggnuplot-file] [ -h] [ -Hcustom-header] [ -I] [ -k] [ -Nrequests] [ -P POST-file] [ -Pproxy-auth-username:password] [ -Q] [ -s] [ -S] [ -Ttimelimit] [ -Tcontent-type] [ -vverbosity] [ -V] [ -W] [ -x<table>-attributes] [ -Xproxy[:port] ] [ -y<tr>-attributes] [ -Z<td>-attributes] [HTTP//]hostname[:port]/path

The parameters of AB are explained in detail

Normal test, with-c-n parameters to complete the task
Format:./ab [Options] [http://]hostname[:p Ort]/path
Parameters:
The total number of requests for the-n test. By default, only one request is executed
-c Number of concurrent requests. The default is one at a time.
-H adds a request header, such as ' Accept-encoding:gzip ', to be requested in gzip mode.
The maximum number of seconds that the-t test takes. Its internal implied value is-n 50000. It allows you to limit the testing of the server to a fixed total time. By default, there is no time limit.
-P contains the files that require post data.
The Content-type header information used by the-t post data.
-V Sets the level of detail that displays information –4 or greater displays header information, 3 or greater values can display response codes (404, 200, etc.), and 2 or greater values can display warnings and other information. -V Displays the version number and exits.
-W outputs the result in the format of an HTML table. By default, it is a table with a two-column width on a white background.
-I executes the head request instead of get.
-c-c Cookie-name=value attach a cookie to the request: line. Its typical form is a parameter pair of Name=value. This parameter can be repeated.

This paper introduces the acquisition and installation of AB and its application examples.

Acquisition and installation of two AB

1 system installation Apache, can be found under the/usr/bin path AB, or Whereis ab.

2 individually installed AB http://www.netingcn.com/install-ab-without-httpd.html

The AB operation needs to rely on the Apr-util package, the installation command is: Yum install Apr-util

Download Apache RPM package, can go directly to the official website manual download, of course, can also use command Yumdownloader to complete, Yumdownloader is Yum-utils package below, if not installed yum-utils, you need to install it first. Since extracting the Apache RPM package will generate the etc, Var, and usr three directories in the current directory, it is recommended that you create a temporary directory with the following command:

mkdir ~/~/abtmpyumdownloader httpdrpm2cpio httpd-*.rpm | Cpio-idmv

After the above command succeeds, you can see a file named AB in the Usr/bin under ~/abtmp, and copy it to the system path, for example.

CP ~/abtmp/usr/bin/ab/usr/bin

Available systems: Win7 Linux, etc.

Three examples

1 HTTP request for Web, e.g. Ab-n 100-c 5 http://baidu.com/

The total number of executions of the #-n request;-c concurrency Number "http://baidu.com/" The URL to be tested
[[email protected] ~]$ ab-n 100-c 5 http://baidu.com/
#首先是Apache的版本信息This is apachebench, Version 2.0.40-dev < $Revision: 1.146 $> apache-2.0Copyright1996 Adam Twiss, Zeus technology LTD, http://www.zeustech.net/Copyright 2006 the Apache Software Foundation, http://www.apache.org/Benchmarking baidu.com (Be patient) ... doneserver software:apache Server Hostname:baidu.com #请求的 Service Server Port:#请求端口Document Path:/       #Document Length:81bytes #页面长度Concurrency level:5 #并发数Time taken fortests:0.125373seconds #总耗时Complete Requests:#总访问次数Failed Requests:0 #注1Write Errors:0Total Transferred:37600bytes #总共传输字节数, including HTML transferred such as header information for http:8100bytes #html字节数, actual page Pass bytes requests per second:797.62 [#/sec] (mean) #每秒多少请求, this is a very important parameter value, the throughput of the server time per request:6.269[MS] (mean) #用户平均请求等待时间Time per request:1.254[MS] (mean, across all concurrent requests) #服务器平均处理时间, which is the reciprocal transfer rate for server throughput:287.14 [kbytes/sec] received #每秒获取的数据长度Connection times (ms) min mean[+/-SD] Median Maxconnect:1 1 0.4) 1 3Processing:3 4 1.2) 4 12Waiting:3 3 1.3) 4 11Total:5 5 1.3) 5 13Percentage of the requests served within a certain time (MS)50% 5 # 50% request returned within 5ms 66% 6 75% 6 80% 6 90% 6 95% 8 98% 11 99% 13 10 0% (Longest request)

Four The following errors occur during the test

1) ab concurrency can not be greater than the number of requests, it will prompt: "Ab:cannot use concurrency level greater than total number of requests"

2) The number of requests by default cannot exceed 1024, it will prompt: "Socket:too many open files (24)"

Use the Ulimit-n command to modify, for example: Ulimit-n 8192 (Sets the maximum number of files that the user can open simultaneously).

3) The concurrency number cannot be greater than 20,000 by default and will prompt "Ab:invalid Concurrency [Range 0..20000]"

Need to modify the Apache source code support directory under the AB.C file, locate: #define Max_concurrency 20000 to change the value of the macro definition, recompile and install Apache.

4) Tip: "Apr_socket_recv:connection reset by Peer (104)" Online said is apr-util some problems, not too stable, try a few times just fine.

5) question: Why is there a failed request about Failed requests? What does this data mean? Whether the test results such as RPS are affected.

A: Can check the file length, as below, length*complete+http header information ≈Total, stating that all requests are issued correctly

Document length:35137 bytes

Complete requests:100

Total transferred:3543782 bytes

When the Failed request is present , a row of data statistics for each cause of failure is given, representing the meaning of each:

Connect fails to send request, destination host connection failed, request is interrupted in the process

Receive is not receiving requests

The length of the response is inconsistent ( based on the value of the content-length header )

Exception An unexpected error occurred

The http Response Header obtained by the HTTP Request after the first 2 Content-length is inconsistent with the first time, it gets the Length error and does not affect the test results.

6) problem: The result gets two responsetime, the difference is very big, what does the two data mean from each other?  

Answer: The following is explained.

AB has a - c n parameter, which is the Concurrency level of the first row , allowing ab to create N a concurrent link test. Their relationship is:tpr1=tpr2*n , Tpr2=1/rps

The first value is calculated with the formula concurrency *timetaken * 5/done While the second value was calculated with The Formula Timetaken * 5

The previous measure of the delay of a single request, the CPU is divided into time slices in turn to perform the request, multiple concurrent cases, a concurrent request takes so long to get the next time slice, the method of calculation for the times per request:60.444 [MS] (mean, Across all concurrent requests) * concurrency number. The popular point is that when you complete the-N 1000 requests with the-C 10 concurrently, add a request to complete the average time required.

The latter measure of performance, which reflects the average time required to complete a request, and the time required to increase a request in the current concurrency situation. Calculation method time taken for tests:60.444 Seconds/complete requests:1000, popular point is that when the-C 10 with the concurrent completion of-n 1001 requests, than the completion of the-n1000 of the request to spend a lot longer.

You can properly adjust the-C and-n sizes to test server performance, and use the HTOP directive to visually view the load of the machine.

Apache-ab Pressure Test Example

Related Article

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.