Use Apache's AB command for pressure measurement

Source: Internet
Author: User

1. Background: The Internet developed today, large and small sites such as springing up, constantly appearing, but want to make a website is very simple, but want to do a site, very very difficult, first: the site after the function of how to do this is secondary, the main is your website can withstand how much traffic, Under high-voltage access, can withstand very high peak access concurrency can be called a good site, then as a programmer, when you set up your site, how should you test your site's concurrent traffic?

The next thing to introduce is Apache's AB command pressure test:

2. Before learning to use the AB command, first understand several concepts of stress testing: (You can go online to check the specific concept)

    1. throughput rate (requests per second)
      Concept: A quantitative description of server concurrency processing power, in REQS/S, Refers to the number of requests processed within a unit of time for a concurrent user. The maximum number of requests per unit of time that a concurrent user could process, called the maximum throughput rate.
      Calculation formula: Total number of requests/time spent processing the number of requests, i.e.
      Request per second = Complete Requests/time taken for tests

    2. Concurrent connections (the number of concurrent connections)
      Concept: The number of requests received by the server at some point, simply speaking, is a session.

    3. Concurrent Users (the number of concurrent users,concurrency level)
      Concept: Note the distinction between this concept and the number of concurrent connections , one user may produce multiple sessions, or the number of connections.

    4. user Average request latency (time per request)
      Calculation formula: Time spent processing all requests completed/(total number of requests/concurrent users), or
      times per Request = time taken for tests/(complete requests/concurrency level)

    5. Server average demand latency (times per req Uest:across all concurrent requests)
      calculates the formula: the number of times/total requests that are processed to complete all requests, that is,
      time taken for/testscomplete request s
      can see that it is the reciprocal of the throughput rate.
      at the same time, it also = user average request Wait time/number of concurrent users, that is
      Request/concurrency level

Introduction to 3.ab ToolsAB is an Apache self-brought stress test tool. AB is very practical, it can not only the Apache server site access stress testing, or other types of servers can be stress testing. such as Nginx, Tomcat, IIS, and so on. Installation:                 1. The company should have a programmer, you can install a wamp or phpstudy, so that the Apache server and MySQL database have, one at a stroke more:file Location: Open the location of Apache you installed: Locate the Ab.exe under the Bin folderOpen a command line under this folder, enter Ab.exe-helplet's explain the options above:
-N is requests, which specifies the total number of executions for the stress test.
- C concurrency, which is used to specify the stress test the number of concurrent numbers.
-T is timelimit, the maximum time (in seconds) to wait for a response.
-B is the buffer size (in bytes) of the WINDOWSIZE,TCP Send/Receive.
-P is postfile, the file to be uploaded when the POST request is sent, and the parameters must also be set -T .
-U is putfile, the file that needs to be uploaded when the put request is sent, and the parameters must also be set -T .
-T is content-type, which sets the Content-type request header information, for example: application/x-www-form-urlencoded , the default value is text/plain .
-V is verbosity, which specifies the level of redundancy for printing help information.
-W Prints the results in an HTML table format.
-I uses a head request instead of a 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 adds a basic network authentication information, separated by a colon between the user name and the password.
-P adds a basic proxy authentication message, separated by a colon between the user name and password.
-X Specifies the proxy server and port number used, for example: "126.10.10.3:88".
-V Prints the version number and exits.
-K uses the KeepAlive feature of HTTP.
-D does not display percentages.
-S does not display prediction and warning messages.
-G outputs the result information to a file in the gnuplot format.
-E Outputs The result information to a file in CSV format.
-R Specifies that the program is not exited when an error message is received.
-H displays usage information, which is actually ab -help .
4. Actual test:

5. Analyze the above test results:

Server software:apache/2.2.25 ( software name and version information)

Server Hostname:www.xxx.com ( host name)

Server port:80 ( servers port)

Document Path:/lol ( URL path for testing)

Document length:0 bytes ( The file size returned by the URL for testing)

Concurrency level:100 ( concurrent number)

Time taken for tests:0.800 seconds ( total times consumed by stress test)

Complete requests:100 ( Total number of stress tests)

Failed requests:0 ( number of failed requests)

Total transferred:16342 bytes ( amount of data transferred)

html transferred:0 bytes (The total amount of data in an HTML document)

requests per second:125.03 [#/sec] (mean) ( average number of requests per second)

Time per request:799.805 [MS] (mean) ( all concurrent users (here is 100) have requested an average of times)

Time per request:7.998 [MS] (mean, across all concurrent requests) ( average time for a single user request)

Transfer rate:19.95 [Kbytes/sec] Received ( transfer rate, Unit: kb/s)

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 let's look at a "pressure Alexander" execution command:

     ab -n 1000 -c 100 localhost/index.php, this time Apache strikes directly--denied access:

D:\study\apache\bin>ab-n 100-c100 http://www.xxx.com;
This is apachebench, Version 2.3 < $Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus technology Ltd, http://www.zeustech.net/Licensed to the Apache software Foundation, HT tp://www.apache.org/  

In the above stress tests, Apache is using the default configuration and has not been processed by any optimization measures. In fact, Apache has been configured to optimize

, the Apache server can hold up to 1000 of the concurrency as long as the server hardware is sufficient.

6.ab of the app interface for pressure measurement:

Ab-n 400-c20 "http://www.xxx.com/api.php?sig= ...";

The interface that will need to be measured, with "";

7.ab pressure measurement for post-pass parameters

Ab-n 400-c20-p parm.txt-t "application/x-www-form-urlencoded" Http://localhost:3000/login

Place Parm.txt in the same folder as Ab.exe, where the parameters that need to be passed in the post format are stored in Parm.txt.

The head of the-t:post request.

Use Apache's AB command for pressure measurement

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.