Hello, everyone, MY name is Xin. This is the 23rd day of my participation in the More text Challenge. For details, see the more text Challenge

Ab Command Introduction

ApacheBench(ab) is often used to stress test web performance and is an essential part of the performance tuning process. The AB command creates a number of concurrent access threads to simulate multiple visitors accessing a URL at the same time. The test target is URL-based, so it can be used to test the stress of Apache as well as other Web servers such as Nginx, Lighthttp, Tomcat, AND IIS.

The ab command has low requirements on the computer that sends the load. It does not occupy much CPU or memory, but creates a huge load on the target server. Therefore, it is a necessary medicine for some DDOS attacks.

Generally, we use the ab command to perform the test locally. For example, one or more Intranet servers are used to perform the test on the Intranet. In this way, the test data will be more accurate.

Install the ab command

[root@gaosh-1 ~]# rpm -qa |grep httpd
httpd-2.215.-69.el6.centos.x86_64
httpd-tools-2.215.-69.el6.centos.x86_64
Copy the code

The ab command is included in httpd-tools, so if you don’t have httpd-tools installed, just use yum to install it

[root@gaosh-1 ~]# yum install httpd-tools
Copy the code

View version:

[root@gaosh-1 ~]# ab -V
This is ApacheBench, Version 2.3 <$Revision$655654: >Copy the code

Parameter of the ab command

[root@gaosh-1 ~]# ab -h
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform  
        ### Number of requests to execute, the total number of pages to visit for this test
    -c concurrency  Number of multiple requests to make   
       ### Number of requests generated at a time (default: concurrency)
    -t timelimit    Seconds to max. wait for responses 
        #### Maximum number of seconds the test takes. The implied internal 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
    
    -p postfile     File containing data to POST. Remember also to set -T
      ### file containing the data to be posted. The file format is "p1= 1&P2 =2". The usage is -p 111.txt. (With -T)
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header for POSTing, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print   
     ### Sets the level of detail to display the information - a value of 4 or more displays header information,
     ####3 or greater displays response codes (404, 200, etc.), and 2 or greater displays warnings and other information.
     
    -w              Print out results in HTML tables
        #### outputs the results in an HTML table. By default, it is a table of two column widths on a white background
    -i              Use HEAD instead of GET
       #### performs a HEAD request, not a GET.
   
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable) -v Print version number and exit ### Print version number [root@gaosh-1 ~]#Copy the code

There are a lot of parameters, but the one we use the most is -n-c-T-p-w, and the frequency is decreasing from left to right

Using an example

1. Use gaosH-64 server to perform pressure test on GaosH-1 server, simulate 10 users, and initiate 1000 requests to Baidu home page
[root@gaosh-64 ~]10 http://192.168.1.22/index.php # ab - 1000 - c n
Copy the code

The version number of the server being tested is displayed during the load test

In IP gaosh – 1; The number of accesses can be viewed on 192.168.1.22

[root@gaosh-1 html]# awk '{print $1}' /var/log/httpd/access_log |sort |uniq -c |sort -n -r
   1000 192.168.1.64
     69 192.168.1.4
Copy the code

You can see that 192.168.1.64 has been accessed 1000 times.

/var/log/httpd/access_log is the HTTPD access log.

2. Pressure test at www.zmkjedu.com

[root@gaosh-64 ~]# ab -n 100 -c 10 www.zmkjedu.com/index.php

In addition to IP, you can also follow the domain name for pressure testing

Detailed information of pressure measurement

[root@gaosh-64 ~]10 http://192.168.1.22/index.php # ab - 1000 - c n
#### version information about ab
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
##### Number of concurrent requests 10, each time 100 requests, each visit is 1000
Benchmarking 192.168.1.22 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

#### Information about the server being testedServer Software: Apache / 2.2.15### Apache version number
Server Hostname:        192.168.1.22    #### IP address of the party being tested
Server Port:            80              ### Port of the server being tested

Document Path:          /index.php    
Document Length:        48709 bytes  ### Size of the requested file

Concurrency Level:      10       #### Concurrency level, 10 at a time
Time taken forTests: 1.186 seconds### Time spent in this pressure test
Complete requests:      1000            #### Total number of requests initiated
Failed requests:        0               ### Failed requests
Write errors:           0
Total transferred:      48881000 bytes   ### Total amount of data transferredHTML transferred: 48709000bytes Total size of index.html file received from server (Requests per second: 843.21) [#/sec] (mean)Time per Request: 11.859 [ms] (mean) Number of requests completed per second: QPS, concurrent Time per Request: 1.186 [ms] (mean, across all concurrent requests) Transfer rate: 40250.90 [Kbytes/ SEC] received Connection Times (ms) 1.186 [ms] (mean, across all concurrent requests) Transfer rate: 40250.90 [Kbytes/ SEC] Received Connection Times (ms)### Corresponding timeMin mean[+/-sd] Median Max Connect: 0 1 3.4 0 45 Processing: 2 10 9.9 7 75 Waiting: 1 6 7.4 4 47 Total: 2 12 10.8 7 81 Percentage of the requests served within a certain time (MS) 50% 7 66% 9 75% 12 80% 16 90% 25 95% 35 98% 48 99% 49 100% 81 (longest request)##### means that 50% of requests are completed in 7 seconds and 99% of requests are completed in less than 49 seconds.
Copy the code

conclusion

The AB tool is a very useful pressure testing tool, of course, there are many other pressure testing tools, I will introduce each of them later, today is mainly related to Apache, this is the fourth apache series of articles.