Configure AB To do stress testing for Nginx servers _nginx

Source: Internet
Author: User
Tags time limit server port

Stress testing is a very important task in operation and maintenance. For example, before a Web site online, can withstand the number of visits, in the case of large traffic performance, these data indicators will directly affect the user experience.
However, there is a common in stress testing, that is, the results of the stress test and the actual load will not be exactly the same, even if the pressure test is done well, can not guarantee 100% and online performance indicators the same. Faced with these problems, we can only try to find ways to simulate. Therefore, the stress test is very necessary, with these data, we can do the maintenance of their own platform to have a good idea.
At present, the more common site stress testing tools are webbench, AB (Apache bench), Tcpcopy, LoadRunner.
Developed by Lionbridge, webbench mainly tests the number of requests per second and data per second, while supporting static, dynamic, SSL, simple deployment, static and dynamic testing. Apply to small Web site stress tests (single cases can simulate up to 30,000 concurrent).
AB (Apache bench) Apache's own pressure test tool, the main function used to test the number of Web site processing requests per second, see more for static stress testing, weak function, unprofessional stress testing tools.
Tcpcopy based on the underlying application request replication, can forward a variety of online requests to the test server, with a distributed pressure testing function, the test data and actual production data is close to the rising star, mainly for medium and large pressure test, all TCP packets can be tested.
LoadRunner pressure testing industry, can create virtual users, can simulate the user's real access process to record as a script, the test results are the most realistic simulation of the most realistic and independent unit test, but the deployment of more complex configuration, need professionals can.
Below, I take AB as an example, to explain how the site before the online stress test is how to do.
AB is a performance testing tool for Apache, and you can install only AB tools.

Ubuntu Installation AB

Apt-get Install Apache2-utils

CentOS Installation AB

Yum Install Httpd-tools

Before testing, you need to prepare a simple HTML, a PHP, a picture file.

Test them separately.

We put the three files in the Nginx installation directory in the default HTML directory,

When we're ready, we can test it.

AB-KC 1000-n 1000 http://localhost/ab.html

This instruction uses 1000 concurrent connections to connect 1000 times. The results are as follows

root@~# AB-KC 1000-n 1000 http://www.nginx.cn/ab.html
This is apachebench, Version 2.3 < $Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.z Eustech.net/licensed to the Apache Software Foundation, http://www.apache.org/Benchmarking www.nginx.cn (is patient) Co  mpleted requests Completed requests Completed-requests Completed requests Completed requests Completed requests Requests Completed-requests Completed 900 requests Completed 1000 requests finished R Equests Server software:nginx/1.2.3 Server Hostname:www.nginx.cn server port:80 document Path:/ab.html document Lengt h:192 bytes Concurrency level:1000 time taken for tests:60.444 seconds Complete requests:1000 Failed requests:139 (C onnect:0, receive:0, length:139, exceptions:0) Write errors:0 non-2xx responses:1000 keep-alive requests:0 Total TR ansferred:732192 bytes HTML transferred:539083 bytes Requests/second:16.54 [#/sec] (mean) <strong>time per re quest: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 <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 Connec t: 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 57 2 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 picture files can use the same instructions, the result I do not post it.

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



The output can be understood literally.

Here are two more important indicators to make a note

Like what

Requests per second:16.54 [#/sec] (mean) time/
request:60443.585 [MS] (mean)

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

Indicates that the current test server can process 16.54 static HTML request transactions per second, followed by mean representing the average. This number represents the overall performance of the current machine, and the larger the value the better.

Time per request:60443.585 [MS] (mean)

A single concurrent delay time, followed by a mean representing an average.
The average time required to complete a single request separately from the current concurrency.

By the way, the difference between two time per request

Time/request:60443.585 [MS] (mean) time/
request:60.444 [MS] (mean, across all concurrent requests)

The previous measurement of the delay of a single request, the CPU is divided into time slices in turn to execute the request, in multiple concurrent cases, a concurrent request to wait so long to get the next time slice.
Calculation method time per request:60.444 [MS] (mean, across all concurrent requests) * Concurrent number

The popular point is that when you complete the-N 1000 request with-C 10, add a request to complete the average time required.

The latter measure of performance, which reflects the average time required to complete a request, and the time it takes to add a request in the current concurrency scenario.
Calculation method time taken for tests:60.444 Seconds/complete requests:1000

The popular point is that when you complete-N 1001 requests with-C 10, it takes more time than-n1000 to complete a request.
You can properly adjust-C and-N size to test server performance, with the help of htop instructions to visually view the load of the machine.

My machine is Sheng mainframe, usually load CPU is 1.7%,htop command results screenshot

After the pressurized load of 100%, the load has been basically up. Htop Command Results screenshot

I think I need to optimize it, or change the machine.

Parameters for AB are explained in detail
a generic test that uses the-c-n parameter to complete the task
format:./ab [Options] [http://]hostname[:p ort]/path
Parameter: The total number of requests for the
-n test. By default, only one request
-C-One concurrent request count is executed. The default is one at a time.
-H adds a request header, such as ' Accept-encoding:gzip ', to be requested in gzip mode. The maximum number of seconds that the
-t test is made. Its intrinsic implied value is-n 50000. It can limit the testing of the server to a fixed total time. By default, there is no time limit. The
-P contains the files that require the data to be post. The Content-type header information used by the
-T post data.
-V Sets the level of detail for displaying information –4 or larger values display header information, 3 or greater values can display response codes (404, 200, and so on), and 2 or greater values can display warnings and other information. -V Displays the version number and exits.
-W outputs the results in HTML table format. By default, it is a table with two columns of white background width.
-I executes the head request rather than get.
-c-c Cookie-name=value Attach a cookie to the request: row. The typical form is a parameter pair of Name=value. This parameter can be repeated.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.