Software stress testing is a basic quality assurance behavior that is part of every important software testing work. Therefore, stress testing is very important, so how to conduct stress testing? In this article, I will share with you a super practical stress testing tool - ab tool (apache bench). I hope it will be helpful to you!
Recommended related video tutorials: "tens of millions of data concurrency solutions (theoretical practice)"
Written in Previously
Before learning the ab tool, we need to understand several concepts about stress testing
Throughput rate (Requests per second)
Concept: A quantitative description of the server's concurrent processing capability, the unit is reqs/s, which refers to the number of requests processed per unit time for a certain number of concurrent users. The maximum number of requests that can be processed per unit time under a certain number of concurrent users is called the maximum throughput rate.
Calculation formula: total number of requests / time taken to process these requests, that is,
Request per second = Complete requests / Time taken for tests
The number of concurrent connections
Concept: The number of requests accepted by the server at a certain time, simply speaking, is a session.
The number of concurrent users (Concurrency Level)
Concept: Pay attention to the difference between this concept and the number of concurrent connections. A user may have multiple sessions at the same time, that is, the number of connections.
User average request waiting time (Time per request)
Calculation formula: time spent processing all requests / (total number of requests / concurrent Number of users), i.e.
Time per request = Time taken for tests / ( Complete requests / Concurrency Level)
Server average request waiting time (Time per request: across all concurrent requests)
Calculation formula: The time it takes to complete all requests/the total number of requests, that is,
Time taken for / testsComplete requests
As you can see, it is the reciprocal of the throughput rate .
At the same time, it also = average user request waiting time/number of concurrent users, that is,
Time per request / Concurrency Level
Ab tool introduction
ab’s full name is: apache bench
ab is a performance testing tool for Apache Hypertext Transfer Protocol (HTTP). Its design intention is to depict the execution performance of the currently installed Apache, mainly to show how many requests per second your installed Apache can handle.
ab is apache’s own stress testing tool. ab is very practical. It can not only perform website access stress testing on the apache server, but also perform stress testing on other types of servers. Such as nginx, tomcat, IIS, etc.
Download ab tool
Go to the apache official website http://httpd.apache.org/ and download apache
Start the ab tool
Take the apache installation path as C:\apache\Apache24\ in the windows environment as an example
Open the terminal and enter the commandcd C:\apache\Apache24\bin
to start ab
Start testing
Enter the commandab -n 100 -c 10 http://test.com/
where -n represents the number of requests, - c represents the number of concurrencies
For other commands, please refer to http://apache.jz123.cn/programs/ab.html
Test result analysis
After the above command is run, the test report will come out
Complete test report
Server information
Document information
Important indicators
Concurrency Level: 100 //并发请求数 Time taken for tests: 50.872 seconds //整个测试持续的时间 Complete requests: 1000 //完成的请求数 Failed requests: 0 //失败的请求数 Total transferred: 13701482 bytes //整个场景中的网络传输量 HTML transferred: 13197000 bytes //整个场景中的HTML内容传输量 Requests per second: 19.66 [#/sec] (mean) //吞吐率,大家最关心的指标之一,相当于 LR 中的每秒事务数,后面括号中的 mean 表示这是一个平均值 Time per request: 5087.180 [ms] (mean) //用户平均请求等待时间,大家最关心的指标之二,相当于 LR 中的平均事务响应时间,后面括号中的 mean 表示这是一个平均值 Time per request: 50.872 [ms] (mean, across all concurrent requests) //服务器平均请求处理时间,大家最关心的指标之三 Transfer rate: 263.02 [Kbytes/sec] received //平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Network consumption time
Response
Questions about login
Sometimes stress testing requires users to log in, what should I do?
Please refer to the following steps:
After logging in with your account and password, use the developer tools to find the cookie value (Session ID) that identifies this session and write it down
If only one Cookie is used, then just type the command:ab -n 100 -C key=value http://test.com/
If you need multiple cookies, just set the Header directly:ab -n 100 -H "Cookie: Key1=Value1; Key2=Value2" http://test.com/
Summary
# Generally speaking, the ab tool ab is small and simple, you can get started and learn quickly, and it can provide the needed Basic performance indicators, but there are no graphical results and cannot be monitored. Therefore the ab tool can be used for temporary emergency tasks and simple testing.
Same type of stress testing tools include: webbench, siege, http_load, etc.
Recommended learning:nginx tutorial
The above is the detailed content of Super practical! Share a stress testing artifact: ab tool. For more information, please follow other related articles on the PHP Chinese website!