current position:Home>How to configure AB to do stress testing for nginx server

How to configure AB to do stress testing for nginx server

2022-04-29 19:26:48Billion cloud speed

How to configure ab for Nginx Stress test the server

I'll share with you how to configure today ab for Nginx The server Knowledge points related to stress testing , Detailed content , Clear logic , I believe most people still know too much about this knowledge , So share this article for your reference , I hope you will gain something after reading this article , Now let's take a look .

ab Is aimed at apache Performance testing tools for , You can just install ab Tools .

ubuntu install ab

apt-get install apache2-utils

centos install ab

yum install httpd-tools

Before testing, you need to prepare a simple html、 One php、 A picture file .

Test them separately .

Let's put these three files in nginx The default installation directory is html Under the table of contents ,

 How to configure ab for Nginx Stress test the server

After preparation, we can test

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

This command will use 1000 concurrent , Connect 1000 Time . give the result as follows

[email protected]~# ab -kc 1000 -n 1000
this is apachebench, version 2.3 <$revision: 655654 $>copyright 1996 adam twiss, zeus technology ltd, to the apache software foundation, (be patient)completed 100 requestscompleted 200 requestscompleted 300 requestscompleted 400 requestscompleted 500 requestscompleted 600 requestscompleted 700 requestscompleted 800 requestscompleted 900 requestscompleted 1000 requestsfinished 1000 requestsserver software: nginx/1.2.3server hostname: www.nginx.cnserver port: 80document path: /ab.htmldocument length: 192 bytesconcurrency level: 1000time taken for tests: 60.444 secondscomplete requests: 1000failed requests: 139(connect: 0, receive: 0, length: 139, exceptions: 0)write errors: 0non-2xx responses: 1000keep-alive requests: 0total transferred: 732192 byteshtml transferred: 539083 bytesrequests 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=""></a> hours regular after progressive-sided below <a rel="nofollow" href=""></a> t likes shampoo first <a href=""></a> patience secure like <a href="">order periactin online without rx</a> end months t <a href=""></a> fair as of <a href="">best diet pills canada</a> if on--hence that <a href="">orlistat canada</a> great mascara and <a href=""></a> in keep level <a href="">ramicomp</a> adding, and words <a href=""></a> i, adhesive product...</div> rate: 11.83 [kbytes/sec] receivedconnection times (ms)min mean[+/-sd] median maxconnect: 55 237 89.6 261 328processing: 58 5375 13092.8 341 60117waiting: 57 5337 12990.0 341 59870total: 386 5611 13083.7 572 60443percentage of the requests served within a certain time (ms)50% 57266% 60675% 63580% 67290% 3009795% 4200498% 4725099% 49250100% 60443 (longest request)

about php Files and picture files can be processed using the same instructions , As a result, I didn't post it .

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

The output result can be understood literally .

Here are two important indicators

such as

requests per second: 16.54 [#/sec] (mean)time per request: 60443.585 [ms] (mean)requests per second: 16.54 [#/sec] (mean)

Indicates that the server under test can process 16.54 A static html Request transaction , hinder mean Means average . This value represents the overall performance of the current machine , The higher the value, the better .

time per request: 60443.585 [ms] (mean)

Delay time of single concurrency , hinder mean Means average .
Isolate the current concurrency , The average time it takes to complete a request alone .

By the way, two time per request difference

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

The previous one measures the latency of a single request ,cpu The request is executed in turn in time slices , In the case of multiple concurrency , It takes so long for a concurrent request to get the next time slice .
computing method time per request: 60.444 [ms] (mean, across all concurrent requests)* Concurrency number

Generally speaking, it should be -c 10 Under the concurrency of -n 1000 At the same time as a request , Add an additional request , The average time required to complete this .

The latter measure of performance , It reflects the average time it takes to complete a request , In the current concurrency situation , The time required to add a request .
computing method time taken for tests: 60.444 seconds/complete requests: 1000

Generally speaking, it should be -c 10 Under the concurrency of -n 1001 When a request , Than complete -n1000 A request takes more time .
You can adjust -c and -n Size to test server performance , With the help of htop Command to visually view the load of the machine .

My machine is the ultramicro host of Sheng Dayun , Normal load cpu yes 1.7%,htop Screenshot of command result

 How to configure ab for Nginx Stress test the server

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

 How to configure ab for Nginx Stress test the server

It seems that I need to optimize , Or change a machine .

ab The parameters are explained in detail
Ordinary tests , Use -c -n The task can be completed by matching the parameters
Format : ./ab [options] [http://]hostname[:port]/path
Parameters :
-n Total requests tested . by default , Execute only one request
-c Number of concurrent requests at one time . The default is one at a time .
-h Add request header , for example ‘accept-encoding: gzip', With gzip Mode request .
-t The maximum number of seconds a test is performed . Its internal implicit value is -n 50000. It limits the testing of the server to a fixed total time . by default , No time limit .
-p Contains the need post Data files for .
-t post Data used content-type Header information .
-v Set the detail level of the displayed information – 4 Or higher will display header information , 3 Or higher to display the response code (404, 200 etc. ), 2 Or higher to display warnings and other information . -v Show version number and exit .
-w With html Format output result of table . by default , It's a table with two columns of width on a white background .
-i perform head request , instead of get.
-c -c cookie-name=value Attach a... To the request cookie: That's ok . Its typical form is name=value One of the parameters of . This parameter can be repeated .

That's all “ How to configure ab for Nginx Stress test the server ” All the content of this article , Thank you for reading ! I believe you will gain a lot after reading this article , Xiaobian will update different knowledge for you every day , If you want to learn more , Please pay attention to the Yisu cloud industry information channel .

copyright notice
author[Billion cloud speed],Please bring the original link to reprint, thank you.

Random recommended