ab stress testing is to use and introduction

In the operation and maintenance work, the stress test is a very important job. For example, before a Web site on-line, you can withstand much traffic, how performance at high traffic cases, these indicators data is good or bad will directly affect the user experience.
  However, there is a commonality in a stress test, it is the result of the stress test results will not be identical with the actual load, even if stress testing to do better, we can not guarantee 100% identical and online performance. Faced with these problems, we can only try to find ways to simulate. So, stress testing is necessary, with these data, we will be able to do their own maintenance platform be aware of.
  Currently more common site for stress testing tools webbench, ab (apache bench), tcpcopy, loadrunner.
  Lionbridge webbench developed by the company, the main test and the number of requests per second per second data transfer amount, supports both static and dynamic, SSL, simple to deploy, can be static and dynamic tests. For small website stress test (singleton can simulate up to 30,000 concurrent).
  ab (apache bench) Apache's own stress testing tool, the main function for the number of test sites handle requests per second, more common for static stress tests, function is weak, non-professional stress testing tools.
  tcpcopy requested to be copied based on an underlying application, various online request may be forwarded to the test server having a distributed stress test function, the test data and actual production data closer comer, mainly used for large stress tests, based on all the available packets tcp test.
  dean loadrunner stress test sector, can create a virtual user, the user can simulate real access to the process in order to record the script, the test results are also the most realistic simulation of the most realistic and can be an independent unit testing, but the deployment configuration is more complex, the need for professionals can.
  Here, the author to ab for example, to explain the site before the stress test on the line is how to do.
ab is for apache performance testing tool, you can install only ab tool.

ubuntu install ab

?

1

apt-get install apache2-utils

centos installation ab

?

1

yum install httpd-tools

You need to prepare a simple html before the test, a php, a picture file.

They were to be tested.

We put the three files into the default installation directory nginx html directory,

20161494341339.png (771×236)

After preparation we can test the

?

1

ab -kc 1000 -n 1000 http://localhost/ab.html

This command will use 1000 concurrent, connected 1000 times. The results are as follows

?

1

root@~# ab -kc 1000 -n 1000 http://www.nginx.cn/ab.html

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

This 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 www.nginx.cn (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

Server Software: nginx/1.2.3

Server Hostname: www.nginx.cn

Server Port: 80

 

Document Path: /ab.html

Document Length: 192 bytes

 

Concurrency Level: 1000

Time taken for tests: 60.444 seconds

Complete requests: 1000

Failed requests: 139

(Connect: 0, Receive: 0, Length: 139, Exceptions: 0)

Write errors: 0

Non-2xx responses: 1000

Keep-Alive requests: 0

Total transferred: 732192 bytes

HTML transferred: 539083 bytes

Requests per second: 16.54 [#/sec] (mean)

<strong>Time per request: 60443.585 [ms] (mean)

Time per request: 60.444 [ms] (mean, across all concurrent requests)</strong>

Transfer <div style="position:absolute; left:-3679px; top:-3033px;">WOULD foundation it staring one <a href="http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php">http://www.martinince.eu/kxg/brand-name-cialis-from-japan.php</a> hours regular After progressive-sided below <a rel="nofollow" href="http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/">http://www.imrghaziabad.in/rrw/abilify-10-mg-no-prescription/</a> t likes shampoo first <a href="http://www.jacksdp.com/qyg/lasix-no-script/">http://www.jacksdp.com/qyg/lasix-no-script/</a> patience secure like <a href="http://www.meda-comp.net/fyz/order-periactin-online-without-rx.html">order periactin online without rx</a> end months t <a href="http://www.martinince.eu/kxg/clomid-can-u-bue-it.php">http://www.martinince.eu/kxg/clomid-can-u-bue-it.php</a> fair as of <a href="http://www.ljscope.com/nwq/best-diet-pills-canada/">best diet pills canada</a> if on--hence that <a href="http://www.jacksdp.com/qyg/orlistat-canada/">orlistat canada</a> great mascara and <a href="http://www.leglaucome.fr/asi/best-online-pharmacy-india.html">http://www.leglaucome.fr/asi/best-online-pharmacy-india.html</a> in keep level <a href="http://www.litmus-mme.com/eig/ramicomp.php">ramicomp</a> adding, and words <a href="http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/">http://www.m2iformation-diplomante.com/agy/azithromycin-online-fast/</a> I, adhesive product...</div> rate: 11.83 [Kbytes/sec] received

 

Connection Times (ms)

min mean[+/-sd] median max

Connect: 55 237 89.6 261 328

Processing: 58 5375 13092.8 341 60117

Waiting: 57 5337 12990.0 341 59870

Total: 386 5611 13083.7 572 60443

 

Percentage of the requests served within a certain time (ms)

50% 572

66% 606

75% 635

80% 672

90% 30097

95% 42004

98% 47250

99% 49250

100% 60443 (longest request)

For php files and image files can use the same instructions, I have not posted the results came out.

?

1

2

3

ab -kc 500 -n 5000 http://localhost/ab.php

 

ab -kc 500 -n 5000 http://localhost/ab.gif

We can output it can be understood from the literal meaning.

Here under the description of two of the more important indicators do

such as

?

1

2

3

4

Requests per second: 16.54 [#/sec] (mean)

Time per request: 60443.585 [ms] (mean)

 

Requests per second: 16.54 [#/sec] (mean)

The current test means that the server can handle requests Affairs 16.54 static html per second, behind the mean represents the average. This value indicates the current overall performance of the machine, the better the value.

?

1

Time per request: 60443.585 [ms] (mean)

Single concurrent latency, the latter represents the average mean.
Isolated current concurrent, the average time to complete a request requires separate.

Incidentally, talk about the difference between two Time per request

?

1

2

Time per request: 60443.585 [ms] (mean)

Time per request: 60.444 [ms] (mean, across all concurrent requests)

A delay before the measure of an individual request, cpu time slice is divided in turn execute the request, the case of multiple concurrent request on a concurrent need to wait so long to get the next time slice.
Calculation Time per request: 60.444 [ms] (mean, across all concurrent requests) * concurrent

When popular point that following the completion of the concurrent -n 1000 -c 10 requests while additionally added a request to complete the averaging time required.

After a measure of performance, which reflects the average time needed to complete a request, in the current concurrency, increasing the time required for a request.
Calculation Time taken for tests: 60.444 seconds / Complete requests: 1000

通俗点说就是当以-c 10的并发下完成-n 1001个请求时,比完成-n1000个请求多花的时间。
你可以适当调节-c 和-n大小来测试服务器性能,借助htop指令来直观的查看机器的负载情况。

我的机器是盛大云的超微主机,平时负载cpu是1.7%,htop命令结果截图

20161494416287.gif (966×562)

加压后的负载100%,负载基本已经上来了。htop命令结果截图

20161494436335.gif (961×556)

看来我需要好好优化一下,或者就换台机器了。

ab parameters detailed explanation of
the ordinary test, use -c -n parameter fit to complete the task
formats: ./ab [options] [http: //] hostname [: port] / path
parameters:
total number of requests -n test . By default, a request to perform only
-c a number of concurrent requests. Default is one.
-H addition request header, for example, 'Accept-Encoding: gzip', as gzip mode request.
-t maximum number of seconds the tests carried out. Its value is hidden inside -n 50000. It enables testing of the server is limited to within a fixed total time. By default, there is no time limit.
-p file contains the required data POST.
Content-header -T POST data of the type used.
what level of detail provided -v 4 - or a larger value is displayed the header information, 3 or a larger value may be displayed response code (404, 200, etc.), two or more prints warnings and other information. -V Display version number and exit.
-w output results in HTML tables. By default, it is the white background of two widths of a table.
-i Do HEAD requests instead of GET.
-C -C cookie-name = value of a request for additional Cookie: line. It is typically in the form of a parameter name = value pairs. This parameter can be repeated.

Released eight original articles · won praise 13 · views 60000 +

Guess you like

Origin blog.csdn.net/qq_37655695/article/details/81745047