There are countless pressure measurement tools on the market, so I will briefly introduce a few commonly used ones.
1 、 Apache ab
ab is a stress testing tool that comes with apache, which is very convenient to use.
installation
1. Ab operation needs to rely on the apr-util package, the installation command is:
yum install apr-util
2. You need the yumdownload command to download. Without this command, you can:
yum install yum-utils
3. Create a new directory for downloading and decompressing:
cd /opt
mkdir abtmp
cd abtmp
yum install yum-utils.noarch
yumdownloader httpd-tools*
rpm2cpio httpd-tools*.rpm | cpio -idmv
4. Copy ./user/bin/ab to the system bin:
cp /opt/abtmp/usr/bin/ab /usr/bin
5. Use the following command to check whether the installation is successful:
ab -V
6. ab --help can perform the required tests
Stress test
Before the pressure test, need to focus on a few options, by ab -help
viewing
Options are:
-n requests 要执行的请求次数
-c concurrency 并发数量
-s timeout 响应时间
carried out:
# 总共100个并发执行1000此请求,超时时间为1s
ab -n 1000 -c 100 -s 1 http://www.baidu.com
2、wrk
wrk is a modern http performance benchmarking tool developed in c language, simple to use and powerful.
installation
You can download the source code from github, compile and install the wrk github address
Stress test
There are not many command options for wrk, it is easy to use
Usage: wrk <options> <url>
Options:
-c, --connections <N> 建立的连接
-d, --duration <T> 执行测试时间
-t, --threads <N> 线程数量
-s, --script <S> 使用lua脚本(非常强大的功能,有兴趣可以深入研究)
-H, --header <H> 为每一个HTTP请求添加HTTP头
--latency 在压测结束后,打印延迟统计信息
--timeout <T> 超时时间
-v, --version Print version details
Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)
# 10个线程100个连接压测30s
wrk -c100 -t10 -d30s http://www.baidu.com
3、JMeter
Apache JMeter is a GUI testing tool written by java with powerful functions and diverse results.
installation
You can go to Apache JMeter to download and install.
use
1. Create a Plan
2. Establish Thread Group
After the Plan is established, the Thread Group can be established. The establishment method: After selecting the Plan, Edit> Add> Threads> Thread Group
Thread Group can set some parameters of the thread, mainly Number of Threads (users) and Loop Count
3. Add Listener
The Listener mainly generates some result reports, and the way to add is: Edit> Add> Listener after selecting Thread Group
You can see that there are many result reports, I usually use the following result reports
-
View Results Tree
-
Aggregate Report
-
Graph Results
-
View Results Table
View Results Tree
This report will generate a request tree, click to view the information of each request
Aggregate Report
This report will generate aggregated statistics of the request, the main parameters are QPS, transmission speed, etc.
Graph Results
Powerful graphical report results
Some explanations of graphical results
-
No of Samples: Represents the number of requests sent to the server
-
Deviation: Represents the distribution of data that changes in the server corresponding to time
-
Latest Sample: Indicates the time when the server responded to the last request
-
Throughtput (throughput rate): here is the amount of data processed by the server per minute
-
Average: Indicates the total running time divided by the number of requests sent to the server
-
Median (median value): means that half of the server time is lower than this value, and the other half is higher than this value
Some analysis based on graphical results
-
The throughput rate was relatively low when it started. As the number of requests increases, the throughput rate first increases and then decreases
-
Deviation is also good to maintain a very stable state if the deviation with the number growing number of requests made, the server increasingly unstable
Reference: https://www.jianshu.com/p/8c622e304e14