The environment of Java necessary skills (linux ab stress test)

linux ab stress test

Test the current limiting function of Nginx built in the previous section. AB test is recommended

What is the AB test?

For the same goal, design two schemes, put the two schemes on the market randomly, let users with the same composition (similar) experience one of the two schemes randomly, and judge which scheme is more effective according to the observation results. The result can be passed CTR or order rate to measure.

1. Introduction to ab

   ab is the abbreviation of apachebench command.

   ab is a stress testing tool that comes with apache. ab is very practical. It can not only perform website access stress test on apache server, but also perform stress test on other types of servers. Such as nginx, tomcat, IIS, etc.

2. The principle of ab

   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.

3. Installation

yum -y install httpd-tools

ab parameter description

 

4. Test version

ab -V

 

[root@vic html]# ab --help
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make
    -t timelimit    Seconds to max. wait for responses
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -p postfile     File containing data to POST. Remember also to set -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
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -h              Display usage information (this message)
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

 

Detailed description:

-n The number of requests executed in the test session. By default, only one request is executed. Total number of requests

-c The number of requests generated at one time. The default is one at a time. Number of users requested

-t The maximum number of seconds for the test. Its internal implicit value is -n 50000, which can limit the server test to a fixed total time. By default, there is no time limit.

-V displays the version number and exits.

Performance indicators of concern before testing:

1 Throughput (Requests per second)

服务器并发处理能力的量化描述,单位是reqs/s,指的是在某个并发用户数下单位时间内处理的请求数。某个并发用户数下单位时间内能处理的最大请求数,称之为最大吞吐率。
记住:吞吐率是基于并发用户数的。这句话代表了两个含义:
a、吞吐率和并发用户数相关
b、不同的并发用户数下,吞吐率一般是不同的
计算公式:总请求数/处理完成这些请求数所花费的时间,即
Request per second=Complete requests/Time taken for tests
必须要说明的是,这个数值表示当前机器的整体性能,值越大越好。

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 accordingly, our number of concurrent users must be divided by this base.

4 Average user request waiting time (Time per request)

计算公式:处理完成所有请求数所花费的时间/(总请求数/并发用户数),即:
Time per request=Time taken for tests/(Complete requests/Concurrency Level)

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

计算公式:处理完成所有请求数所花费的时间/总请求数,即:
Time taken for/testsComplete requests
可以看到,它是吞吐率的倒数。
同时,它也等于用户平均请求等待时间/并发用户数,即
Time per request/Concurrency Level

 

 

5. Test

  Ab pressure test Nginx default page as a demonstration:

There are many command parameters for ab, and we often use the -c and -n parameters.

[root@localhost usr]# ab -c 100 -n 10000 http://127.0.0.1/index.html
#同时处理1000个请求并运行10次index.html
#-c100表示并发用户数为100
#-n10000表示请求总数为10000 

#简单使用说明

./ab -c 100 -n 10000 http://127.0.0.1/index.html

#-c 100 即:每次并发100个

#-n 10000 即: 共发送10000个请求

6. Explanation

[root@zhy html]# ab -n100 -c10 127.0.0.1/index.html
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/

Benchmarking 127.0.0.1 (be patient).....done


Server Software:        Apache    #测试服务器的名字
Server Hostname:        127.0.0.1    #请求的URL主机名
Server Port:            80    #web服务器监听的端口

Document Path:          /index.php    #请求的URL中的根绝对路径
Document Length:        211 bytes    #HTTP响应数据的正文长度

Concurrency Level:      10    # 并发用户数,即-c10
Time taken for tests:   0.010 seconds    #所有这些请求被处理完成所花费的总时间 单位秒
Complete requests:      100    # 总请求数量,即-n100
Failed requests:        0    # 表示失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况
Write errors:           0
Non-2xx responses:      100
Total transferred:      41000 bytes    #所有请求的响应数据长度总和。包括每个HTTP响应数据的头信息和正文数据的长度
HTML transferred:       21100 bytes    # 所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
Requests per second:    9994.00 [#/sec] (mean)    #吞吐率,计算公式:Complete requests/Time taken for tests  总请求数/处理完成这些请求数所花费的时间
Time per request:       1.001 [ms] (mean)    # 用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level),处理完成所有请求数所花费的时间/(总请求数/并发用户数)
Time per request:       0.100 [ms] (mean, across all concurrent requests)    #服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level
Transfer rate:          4001.51 [Kbytes/sec] received    #表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量。

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   0.1      1       1
Waiting:        0    1   0.1      1       1
Total:          1    1   0.1      1       1

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      1 (longest request)

#Percentage of requests served within a certain time(ms)这部分数据用于描述每个请求处理时间的分布情况,比如以上测试,100%的请求处理时间都不超过1ms,这个处理时间是指前面的Time per request,即对于单个用户而言,平均每个请求的处理时间

The most relevant high-availability and high-performance parameters of Internet software, the request response distribution after ab pressure test (the following figure shows a very important parameter)

 

Guess you like

Origin blog.csdn.net/Coder_Boy_/article/details/110424702