Linux learning 11-CentOS install ab for stress test

Preface

Website performance stress test is an indispensable part of the server website performance tuning process. After the test environment is ready, how to perform stress test on the website?
There are many tools for stress testing, such as: ab, http_load, webbench, siege, jmeter, lr, locust. This article introduces a lightweight stress testing tool ab, which is very easy to use.

Introduction to ab(apachebench)

ApacheBench is a web stress testing tool that comes with Apache server, referred to as ab.
ab is also a command line tool, which has very low requirements for the local machine that initiates the load. According to the ab command, many concurrent access threads can be created to simulate multiple visitors accessing a URL address at the same time, so it can be used to test the target server Load pressure.
In general, the ab tool is small and simple, quick to learn, and can provide the basic performance indicators needed, but it has no graphical results and cannot be monitored.

The principle of ab: the ab command will create multiple concurrent access threads to simulate multiple visitors accessing a URL address at the same time.
Its test target is based on URL. Therefore, it can be used to test the load pressure of apache as well as the pressure of other web servers such as nginx, lighthttp, tomcat, and IIS.

The ab command has very low requirements on the computer issuing the load. It neither uses a high CPU nor a lot of memory.
But it will cause a huge load to the target server, and the principle is similar to a CC attack. You also need to pay attention to your own testing and use, otherwise there will be too much load at one time. It may cause the target server to run out of resources, or even crash.

ab performance indicators

There are several indicators that are more important in the process of performance testing:

1.Throughput rate (Requests per second)

A quantitative description of the concurrent processing capability of a server, in reqs/s, which refers to the number of requests processed per unit time under a certain number of concurrent users. The maximum number of requests that can be processed per unit time for a certain number of concurrent users is called the maximum throughput rate.

Remember: the throughput rate is based on the number of concurrent users. This sentence represents two meanings:

2.The number of concurrent connections

The number of concurrent connections refers to the number of requests accepted by the server at a certain time. Simply put, it is a session.

3.Number of concurrent users (Concurrency Level)

Pay attention to the difference between this concept and the number of concurrent connections. A user may have multiple sessions at the same time, that is, the number of connections. Under HTTP/1.1, IE7 supports two concurrent connections, IE8 supports 6 concurrent connections, and FireFox3 supports 4 concurrent connections, so correspondingly, our number of concurrent users must be divided by this base.

4.Average user request waiting time (Time per request)

Calculation formula: the time it takes to process all requests/(total requests/concurrent users), namely:

Time per request=Time taken for tests/(Complete requests/Concurrency Level)

5.Server average request waiting time (Time per request: across all concurrent requests)

Calculation formula: the time taken to complete all the requests/total number of requests, namely:

Time taken for/testsComplete requests

As you can see, it is the inverse of the throughput rate. At the same time, it is also equal to the average user request waiting time/the number of concurrent users, that is

Time per request/Concurrency Level

ab install

Installing ab under centos is very simple, you can install it directly with yum

yum install -y httpd-tools

[ root@yoyo ~]# yum install -y httpd-toolsDependencies Resolved=================================================================================================================================
Package                        Arch                      Version                                  Repository               Size
=================================================================================================================================
Installing:
httpd-tools                    x86_64                    2.4.6-88.el7.centos                      base                     90 k
Installing for dependencies:
apr                            x86_64                    1.4.8-3.el7_4.1                          base                    103 k
apr-util                       x86_64                    1.5.2-6.el7                              base                     92 kTransaction Summary
=================================================================================================================================
Install  1Package(+2 Dependent packages)Total download size:286 k
Installed size:584 k
Downloading packages:(1/3): apr-util-1.5.2-6.el7.x86_64.rpm                                                                    |92 kB  00:00:00(2/3): apr-1.4.8-3.el7_4.1.x86_64.rpm                                                                     |103 kB  00:00:00(3/3): httpd-tools-2.4.6-88.el7.centos.x86_64.rpm                                                         |90 kB  00:00:00---------------------------------------------------------------------------------------------------------------------------------
Total                                                                                            1.0 MB/s |286 kB  00:00:00    
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : apr-1.4.8-3.el7_4.1.x86_64                                                                                    1/3
 Installing : apr-util-1.5.2-6.el7.x86_64                                                                                   2/3
 Installing : httpd-tools-2.4.6-88.el7.centos.x86_64                                                                        3/3
 Verifying  : httpd-tools-2.4.6-88.el7.centos.x86_64                                                                        1/3
 Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                   2/3
 Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                                                                    3/3Installed:
 httpd-tools.x86_64 0:2.4.6-88.el7.centos                                                                                      Dependency Installed:
 apr.x86_64 0:1.4.8-3.el7_4.1                                   apr-util.x86_64 0:1.5.2-6.el7                                  Complete!

After the installation is complete, use ab -V to view the version number Version 2.3

[ root@yoyo sbin]# ab  -V
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/

To view the help information, use ab -help, the most important of which are -c concurrent number and -n total number of connections

[ root@yoyo sbin]# ab -help
Usage: ab [options][http[s]://]hostname[:port]/path
Options are:-n requests To execute the total number of requests, one request will be executed by default
 - c concurrency The number of multiple requests executed at once, which is the number of concurrent
 - t timelimit is the maximum number of seconds used for benchmarking. Use it to benchmark the server in a fixed total time. By default, there is no time limit.
 - s timeout The maximum number of seconds to wait before timing out. The default value is 30 seconds.
 - b windowsize TCP send/The size of the receive buffer, in bytes.
 - B address The address to be bound when making outgoing connections.
 - p postfile The file containing data to POST. Also remember to set-T。
 - u putfile A file containing PUT data. Also remember to set-T 。
 - T content-type  Content-type is used for POST/The content type content type title of the PUT data, for example:'application/x-www-form-urlencoded'Default is' 'text/plain'
 - v verbosity verbosity How many troubleshooting information to print, set the detailed level-4 and above print header information, 3 and above print response code (404,200 etc.), 2 and above print warnings and messages.
 - w Output results in HTML table format. By default, it is a two-column table with a white background.
 - i Perform HEAD request instead of GET.
 - x attributes are used as<table>The attribute string. Attribute is inserted<table here>。
 - y attributes are used as<tr>The attribute string.
 - z attributes are used as<td>The attribute string.
 - C attribute adds the cookie to the request. Parameters are usually named=The form of value pairs. This field is repeatable.
 - H attribute such as&#39;Accept-Encoding:gzip&#39; after inserting all normal header lines-A attribute adds basic WWW authentication, this attribute is a colon separated username and password, auth-username:password   -P attribute adds basic proxy authentication, the attribute is a user name and password separated by a colon, proxy-auth-username:password   -X proxy:port uses the proxy server and port number.
 - V Print the version number and exit.
 - k Use HTTP KeepAlive function.
 - d Do not display the percentile service table.
 - S Don&#39;t show confidence estimates and warnings.
 - q Do not show progress when making more than 150 requests.
 - g filename Output the collected data to a gnuplot format file.
 - e filename Outputs a CSV file providing percentages.
 - r Do not exit the socket receiving error.
 - h Display usage information (this message).
 - Z ciphersuite ciphersuite specifies SSL/TLS cipher suite (see openssl cipher)
 - f protocol specifies SSL/TLS protocol(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

ab stress test example

The number of concurrent requests is 10, a total of 100 requests are sent, the test address: http://47.104.xx:81/, if there is no test environment, you can try pressure test Baiduhttps://www.baidu.com/

ab -c 10 -n 100 http://47.104.x.x:81/

[ root@yoyo sbin]# ab -c 10-n 100 http://47.104.x.x:81/
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/
# - - - - - - - - - - - - - The above ab related version information-------------------------#Benchmarking 47.104.x.x(be patient).....doneServer Software:        nginx/1.12.0                      #Server software version
Server Hostname:47.104.x.x                       #Requested URL
Server Port:81                                        #The requested port number Document Path:/                                       #The path of the requested server
Document Length:11270 bytes                   #The unit of the length of a single request page is byte Concurrency Level:10                                   #Concurrency
Time taken for tests:19.130 seconds                #Total time-consuming 124s
Complete requests:100                                  #Total requests
Failed requests:0                                       #Failed request
Write errors:0                                            
Total transferred:1140400 bytes                      #The total number of bytes transmitted http header information
HTML transferred:1127000 bytes                     #The number of bytes transferred in the actual page
Requests per second:5.23[#/sec](mean)           #How many requests per second
Time per request:1913.021[ms](mean)           #How long does each user wait on average
Time per request:191.302[ms](mean, across all concurrent requests)  #How long does the server take on average to process
Transfer rate:58.22[Kbytes/sec] received        #How much data is obtained per second Connection Times(ms)
      min  mean[+/-sd]     median     max
Connect:040197.201002
Processing:218241687.0142610556
Waiting:18131199.94388754
Total:218641679.41429       10556Percentage of the requests served within a certain time(ms)50%1429                 # 50%The user’s request is returned within 1429ms
 66 %203575%249380%284590%344995%517498%785599%10556100%10556(longest request)

Note that the general test environment server and the stress test ab server should not be the same, otherwise it will affect the entire result

Recommended Posts

Linux learning 11-CentOS install ab for stress test
Linux Centos7 install jdk1.8
CentOS (linux) install PostgreSQL
Centos 7 install JDK (Linux install jdk)
Know Linux and install CentOS
Linux Centos7 install redis tutorial
Install MySQL 8.0.16 on Linux Centos
Install MySQL under Linux (CentOS 7)
CentOS 6.8 under linux install mongodb
CentOS8 install MySQL8 (pro test)
Linux CentOS 7 install JDK detailed steps
Install MySQL on Linux CentOS7 (Windows)
​Install Oracle database on CentOS Linux
Linux CentOS6 compile and install Pyt
Use VMware15 to install Linux (CentOS6.5)
Install Jenkins on linux centos (non-docker way)
Install mysql8.0.13 version under Linux CentOS7 system
1.5 Install Centos7
Novice learning Linux (eight) ---- MySql installation (Centos7)
How to install RPM packages on CentOS Linux
Install MySQL 5.7 under CentOS 7 for middle class children!
Linux (CentOS7) using RPM to install mysql 8.0.11 tutorial
How to install Linux CentOS 7.7 system through VMware
Centos6 install Python2.7.13
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
Centos7 install Python 3.6.
CentOS 7 install Docker
CentOS7 install GlusterFS
CentOS 7.4 install Zabbix 3.4
CentOS7 install Docker
Centos6.5 install Tomcat
CentOS install Python 3.6
Vmware install CentOS6
centos7 install docker-ce 18.01.0
CentOS 7.2 install MariaDB
Centos7 install Python2.7
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
Linux01 install centOS6.5mini
CentOS6 install mist.io
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
Centos install Python3
centos7 install docker
CentOS install jdk
centos7 install nginx-rtmp
CentOS8 install MySQL8.0
Centos6.3 install KVM
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS 7 install Java 1.8