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 |
|
centos installation ab
1 |
|
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,
After preparation we can test the
1 |
|
This command will use 1000 concurrent, connected 1000 times. The results are as follows
1 |
|
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 |
|
For php files and image files can use the same instructions, I have not posted the results came out.
1 2 3 |
|
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 |
|
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 |
|
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 |
|
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命令结果截图
加压后的负载100%,负载基本已经上来了。htop命令结果截图
看来我需要好好优化一下,或者就换台机器了。
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.