Use ab to stress test nginx (ab performance stress test case)

This article is transferred from http://www.nginx.cn

Nginx is famous for its high concurrency and memory saving.

I believe that most students who install nginx want to know how their nginx performance is.

I would like to share with you my stress testing method and results using the ab tool,

ab is a performance testing tool for apache, you can only install the ab tool.

ubuntu install ab

apt-get install apache2-utils

centos install ab

yum install httpd-tools

 

Before the test, you need to prepare a simple html, a php, and an image file.

Test them individually.

We put these three files in the default html directory of the nginx installation directory,

 

 

Once ready we can test

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

This command will use 1000 concurrency and make 1000 connections. The result is as follows

root@~# ab -kc 1000 -n 1000 http://www.nginx.cn/ab.htmlThisisApacheBench,Version2.3<$Revision:655654 $>Copyright1996AdamTwiss,Zeus)Completed100 requests
Completed200 requests
Completed300 requests
Completed400 requests
Completed500 requests
Completed600 requests
Completed700 requests
           TechnologyLtd, http://www.zeustech.net/Licensed to TheApacheSoftwareFoundation, http://www.apache.org/Benchmarking www.nginx.cn (be patient           Completed800 requests
Completed900 requests
Completed1000 requests
Finished1000 requests
ServerSoftware: nginx/1.2.3ServerHostname      : www.nginx.cn
ServerPort:80DocumentPath:/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] receivedConnectionTimes(ms)
min mean[+/-sd] median max
Connect:5523789.6261328Processing:58537513092.834160117Waiting:57533712990.034159870Total:386561113083.757260675%63580%67290%                      60443Percentage of the requests served within a certain time (ms)50%57266%     3009795%4200498%4725099%49250100%60443(longest request)     

You can use the same instructions for php files and image files, but I won't post them.

 

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

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

 

The output result can be understood literally.

Here are two more important indicators to explain

for example

Requests per second: 16.54 [#/sec] (mean)
Time per request: 60443.585 [ms] (mean)

Requests per second: 16.54 [#/sec] (mean)
means that the currently tested server can process 16.54 static html request transactions per second, and the mean behind means the average. This value represents the overall performance of the current machine, and the larger the value, the better.

Time per request: 60443.585 [ms] (mean)
The delay time of a single concurrency, the mean behind represents the average.
The average time required to complete a single request in isolation from the current concurrency.

By the way, let's talk about the difference between the two Time per request

Time per request: 60443.585 [ms] (mean)
Time per request: 60.444 [ms] (mean, across all concurrent requests)
The previous one measures the delay of a single request. The CPU executes requests in turn in time slices. In the case of multiple concurrency , a concurrent request needs to wait so long to get the next time slice.
Calculation method Time per request: 60.444 [ms] (mean, across all concurrent requests)*concurrency

In layman's terms, when -n 1000 requests are completed under the concurrency of -c 10, an additional request is added to complete the average time required.

The latter measure of performance, it reflects the average time required to complete a request, in the current concurrency situation, increase the time required for a request.
Calculated Time taken for tests: 60.444 seconds/Complete requests: 1000

In layman's terms, it takes more time to complete -n 1001 requests than to complete -n1000 requests with the concurrency of -c 10.
You can adjust the size of -c and -n appropriately to test the server performance, and use the htop command to visually check the load of the machine.

My machine is the Super Micro host of Shanda Cloud, the usual load cpu is 1.7%, screenshot of htop command result

 

The load after pressurization is 100%, and the load has basically come up. Screenshot of htop command result

 

It seems that I need to optimize it, or change the machine.

----------------

Detailed explanation of the parameters of ab

For ordinary tests, you can use the -c -n parameters to complete the task
format: ./ab [options] [http://]hostname[:port]/path
parameters:
-n The total number of requests for the test. By default, only one request is executed
-c the number of concurrent requests at a time. The default is one at a time.
-H Add request header, such as 'Accept-Encoding: gzip', to request in gzip mode.
-t Maximum number of seconds to test. Its internal implicit value is -n 50000. It can limit the testing of the server to a fixed total time. By default, there is no time limit.
-p The file containing the data to be POSTed.
-T The Content-type header used by the POST data.
-v Sets the verbosity of the displayed information – 4 or more displays headers, 3 or more displays response codes (404, 200, etc.), 2 or more displays warnings and other information. -V Display the version number and exit.
-w Output results in HTML table format. By default, it is a table with a width of two columns on a white background.
-i Do a HEAD request, not a GET.
-C -C cookie-name=value Append a Cookie: line to the request. Its typical form is an argument pair of name=value. This parameter can be repeated.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326994131&siteId=291194637