pressure
A simple, java-based, http server stress test tool, git address
Cause
- jmeter dynamic scripting is more complicated
- Hope that the stress test program can be executed on the server side, and initiate a request from the intranet environment
- There is enough room for expansion to facilitate pressure testing of complex processes
rely
- JDK 8
- Maven
Quick start
Construct
- Execute git command
git clone https://github.com/NotInWine/pressure.git
- Import your idea
- Build the project using pom.xml
步骤略过
Examples
package com.pressure;
/**
* 测试
*
* @author YL
*/
public class Main {
public static void main(String[] args) {
/**
* 获取请求处理器
* 总请求次数等于循环次数 * RequestInfo 脚本长度
* @param poolSize 线程池并发线程数量
* @param requestSize 循环请求次数
*/
RequestInterface requestInterface = RequestImpl.build(
500,
5000)
.setContentTimeOut(3000) // 链接超时时间 毫秒
.setSocketTimeOut(5000) // 响应超时时间 毫秒
.setMonitors(
/**
* 设置监听(收集统计压测记录)
* 目前自带两个款监听器
* @see com.pressure.core.httputil.impl.LogResultInfoMonitor 日志记录
* @see com.pressure.core.httputil.impl.SummaryMonitor 汇总打印
*
* 想要实现自定义的监听器可实现:
* @see com.pressure.core.httputil.ResultInfoMonitor
* 在此处配置给处理器
*/
new LogResultInfoMonitor(new File("D:\\big_folder\\log.txt")),
new SummaryMonitor()
);
// 配置请求脚本
requestInterface.send(
new RequestInfo(
"列表",
"https://www.xxxxxx.com/api/video/pay/start?start=1&count=15&keyWord=",
RequestInfo.RequestMethod.GET
),
new RequestInfo(
"详情(包含动态参数)",
"https://www.xxxxxx.com/api/video/playDetail?videoId=${data.data.$2.id}&token=",
RequestInfo.RequestMethod.GET
),
new RequestInfo(
"子列表(包含动态参数)",
"https://www.xxxxxx.com/api/video/getVideList?recordId=${data.videoId}&type=video",
RequestInfo.RequestMethod.GET
),
new RequestInfo(
"子列表详情(包含动态参数)",
"https://www.xxxxxx.com/api/video/playDetail?videoId=${data.$1.id}&token=",
RequestInfo.RequestMethod.GET
)
);
}
}
Sample output
- LogResultInfoMonitor log
batchId=4752, name=子列表(包含动态参数), state=SUCCESS, httpLog=HttpLog{url='https://xkx.aiyingli.com/api/video/getVideList?recordId=245&type=video', httpState=200, params=null
, requestHeaders=null
, responseHeaders=[Server: nginx, Date: Sun, 19 Apr 2020 04:59:12 GMT, Content-Type: application/json; charset=utf-8, Transfer-Encoding: chunked, Connection: keep-alive, X-Powered-By: PHP/5.5.38, Access-Control-Allow-Origin: *]
, responseBody='{"code":1,"msg":"success","time":"1587272352","data":[{]}'}
, time=4260
- SummaryMonitor
子列表:{, 最慢响应=9121, 最快响应=57, 平均响应=2533, 总请求次数=4072, 请求异常次数=301, 异常率=0.0739}
详情:{, 最慢响应=5819, 最快响应=56, 平均响应=2501, 总请求次数=4438, 请求异常次数=366, 异常率=0.0825}
列表:{, 最慢响应=10718, 最快响应=48, 平均响应=2862, 总请求次数=5000, 请求异常次数=562, 异常率=0.1124}
子列表详情:{, 最慢响应=5086, 最快响应=54, 平均响应=2489, 总请求次数=3771, 请求异常次数=272, 异常率=0.0721}
汇总:{吞吐量(qps)=189.90, 最慢响应=10718, 最快响应=48, 平均响应=2610, 总请求次数=17281, 请求异常次数=1501, 异常率=0.0869}
Package execution
Need to be packaged to the server to execute the editable example , and then use mvn install, marked as an executable jar, and execute it on (server | PC) java -jar
Key concept
- The controller RequestInterface
is responsible for the core logic of the pressure test request, responsible for http connection configuration, request sending, and trigger statistics (calling the listener) - The request command package RequestInfo
encapsulates the request instruction, which is passed as a parameter to the controller for execution. - The listener ResultInfoMonitor
handles the pressure test results and currently supports two listeners, receiving response logs- Log
- Summary monitoring
As the most scalable part, you can use the listener to customize various forms of statistical output