Apache AB pressure concurrency test tool

Source: Internet
Author: User
Tags server port

When you use PHP (or other programming language) to complete a Web application development, and the Web program is running on the Apache server, have you ever considered some stress tests on your Apache server and the Web program on which it was deployed? After all, gold, as long as the configuration is reasonable, the program code running good performance, the hardware can withstand, through the pressure test we will be able to see a gratifying result. Then again, even if the test results are poor or bad, we can reflect on them and find out where the problem is. Saying so much nonsense, in fact, is to tell you: the server and the website program stress testing is necessary.

It's very simple to stress test Apache and its web programs, and we don't have to download any additional test tools to install, because Apache HTTP Server has prepared a stress test tool for--ab.

AB, Apache Benchmark, can be found in Apache's installation directory as long as we have Apache installed. Its residential address is Apache安装目录/bin/ab.exe . Now, let's take a look at how to use Ab.exe for stress testing.

Before using it, let's learn AB's usage first. First, we enter CMD to open the DOS window and then change the current working directory to: Apache安装目录/bin/ . Then type the help command ab -help (or ab /? , ab -h ) and we can see the following usage interface.

Common commands: Ab-n 1000-c 127.0.0.1/index.php//Use absolute path! 1000 Access concurrency is 10

Introduction to AB Usage

As you can tell by the above usage, the use of AB is to enter the following DOS command:

[Optional parameter options]   URLs that require stress testing

In addition, we will learn more about the role of each parameter option based on the usage interface described above.

-N
the requests is used to specify the total number of executions of the stress test.
-C
that is concurrency, which specifies the number of concurrency for a stress test.
-T
that is timelimit, the maximum time (in seconds) to wait for a response.
-B
that is, the buffer size (in bytes) of the WINDOWSIZE,TCP Send/Receive.
-P
that is, Postfile, the file to be uploaded when the POST request is sent, and the parameters must also be set -T .
-U
that is, Putfile, the file that needs to be uploaded when the put request is sent, and the parameters must also be set -T .
-T
The
Content-type, which is used to set the Content-type request header information, for example: application/x-www-form-urlencoded , the default value is text/plain .
-V
that is verbosity, specifies the level of redundancy for printing help information.
-W
prints the results in an HTML table format.
-I.
use head request instead of GET request.
-X
inserts a string as a property of the table label.
-Y
inserts a string as a property of the TR label.
-Z
inserts a string as a property of the TD label.
-C
Add cookie information, for example: "apache=1234" (You can repeat this parameter option to add multiple).
-H
Add any request header, for example: "Accept-encoding:gzip", the request header will be added after the existing multiple request headers (you can repeat the parameter option to add multiple).
-A
Add a basic network authentication information, separated by a colon between the user name and the password.
-P
Add a basic proxy authentication message, separated by a colon between the user name and the password.
-X
Specify the proxy server and port number to use, for example: "126.10.10.3:88".
-V
Print the version number and exit.
-K
Use the KeepAlive feature of HTTP.
-K
Use the KeepAlive feature of HTTP.
-D
does not display percentages.
-S
no estimate and warning messages are displayed.
-G
outputs the resulting information to a file in the gnuplot format.
-E
output The result information to a file in CSV format.
-R
Specifies that the program is not exited when an error message is received.
-H
Show usage information, actually ab -help .

Although AB can be configured with more parameter options, in general we only need to use ab -n 数字 -c 数字 url路径 the shape of the command. For example, we are on the local Apache server, the URL is localhost/index. the PHP page for stress testing. The total number of tests was 1000, and the number of concurrent sessions was 100 (equivalent to 100 users accessing them concurrently, with a total of 1000 visits). We entered the DOS command ab -n 1000 -c 100 localhost/index.php and printed the results as follows:

F:\apache2.2\bin>ab-n 1000-c Localhost/index.phpthis is apachebench, Version 2.3 < $Revision: 655654 $>copyr Ight 1996 Adam Twiss, Zeus technology LTD, http://www.zeustech.net/Licensed to the Apache software Foundation, http://www. apache.org/benchmarking localhost (be patient) completed requestscompleted requestscompleted 300 requestscompleted requestscompleted requestscompleted requestscompleted requestscompleted 800 requestscompleted requestscompleted requestsfinished, Requestsserver software:apache/2.2.25 (Server Software name and version information) server Hostname:localhost (Server host name) server PORT:80 (Server port) Document Path:/index.PHP (URL path for testing) Document length:10 bytes (The document size returned by the URL for testing) Concurrency level:100 (Concurrent number) time taken for tests:0.247 seconds (Total time spent on stress tests) complete requests:1000 ( Total number of stress tests) Failed requests:0 ( Number of failed requests) Write errors:0 ( number of network connection write errors) total transferred:198000 bytes (html document total data) requests per second:4048.34 [#/sec] (mean) ( average number of requests per second) time per request:24.701 [MS] (mean) (per request:0.247 [ms ] (mean, across all concurrent requests) ( Transfer rate, Unit: KB/S) Connection times (ms) min MEAN[+/-SD] Median maxconnect:0 0 0.3 0 1processing:6 29Total 4.2 30waiting:5 : 6 4.2 30Percentage of the requests served within a certain time (MS) 50% 24 66% 25 75% 26 80% 26 90% 27 95% 27 98% 99% 100% (Longest request)           

In the above test, the total number of stress tests we set and the number of concurrency did not make the server feel any "pressure", now we look at a "pressure Alexander" execution command: ab -n 100000 -c 1000 localhost/index.php , this time Apache directly strike-denied access:

F:\apache2.2\bin>ab-n 100000-c Localhost/index. Phpthis is apachebench, Version 2.3 < $Revision: 655654 $>copyright 1996 Adam Twiss, Zeus technology LTD,/HTTP Www.zeustech.net/Licensed to the Apache software Foundation, http://www.apache.org/Benchmarking localhost (be patient) C4/>test aborted after Failuresapr_socket_connect (): Unable to connect because the target computer was actively rejected.   (730061)

Note: In the above stress test, Apache is using the default configuration and has not been processed by any optimization measures. In fact, after configuration optimization, Apache server can hold up to 1000 concurrency as long as the server hardware is sufficient.

Test the concurrency of Redis

<?Php$redis =new Redis ();  $redis->connect (' 127.0.0.1 ', 6379 $time = date (" Ymd h:i:s " $redis->rpush (' List1 ',  $time echo "queue total length:".  $redis->llen (' List1 ' echo "<br/>" ; /* while (true) {//out pair $get = $redis->lpop (' list '); if ($ Get) {echo ' Out of queue-'. $get; Echo ' <br/> ';} else {echo ' completes '; return false;} */            

Apache AB pressure concurrency test tool

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.