mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: use gatling to have a presure test for remote framework
This commit is contained in:
parent
24b4cc4eb5
commit
0d29b6369a
@ -2,9 +2,11 @@ package tech.powerjob.remote.benchmark;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import tech.powerjob.common.enums.Protocol;
|
||||
import tech.powerjob.remote.framework.BenchmarkActor;
|
||||
import tech.powerjob.remote.framework.base.Address;
|
||||
import tech.powerjob.remote.framework.base.HandlerLocation;
|
||||
@ -32,29 +34,42 @@ public class PressureTestController {
|
||||
@Resource
|
||||
private EngineService engineService;
|
||||
|
||||
@GetMapping("/httpTell")
|
||||
public void httpTell(Integer blockMs, Integer responseSize, String content) {
|
||||
@GetMapping("/tell")
|
||||
public void httpTell(String protocol, Integer blockMs, Integer responseSize, String content) {
|
||||
URL url = new URL().setLocation(HL).setAddress(new Address().setPort(SERVER_HTTP_PORT).setHost(HOST));
|
||||
final BenchmarkActor.BenchmarkRequest request = new BenchmarkActor.BenchmarkRequest().setContent(content).setBlockingMills(blockMs).setResponseSize(responseSize);
|
||||
try {
|
||||
engineService.getHttpTransporter().tell(url, request);
|
||||
if (Protocol.HTTP.name().equalsIgnoreCase(protocol)) {
|
||||
engineService.getHttpTransporter().tell(url, request);
|
||||
} else {
|
||||
engineService.getAkkaTransporter().tell(url, request);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[HttpTell] process failed!", e);
|
||||
ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/httpAsk")
|
||||
public void httpAsk(Integer blockMs, Integer responseSize, String content, Boolean debug) {
|
||||
|
||||
@GetMapping("/ask")
|
||||
public void httpAsk(String protocol, Integer blockMs, Integer responseSize, String content, Boolean debug) {
|
||||
URL url = new URL().setLocation(HL).setAddress(new Address().setPort(SERVER_HTTP_PORT).setHost(HOST));
|
||||
final BenchmarkActor.BenchmarkRequest request = new BenchmarkActor.BenchmarkRequest().setContent(content).setBlockingMills(blockMs).setResponseSize(responseSize);
|
||||
try {
|
||||
CompletionStage<BenchmarkActor.BenchmarkResponse> responseOpt = engineService.getHttpTransporter().ask(url, request, BenchmarkActor.BenchmarkResponse.class);
|
||||
CompletionStage<BenchmarkActor.BenchmarkResponse> responseOpt = null;
|
||||
|
||||
if (Protocol.HTTP.name().equalsIgnoreCase(protocol)) {
|
||||
responseOpt = engineService.getHttpTransporter().ask(url, request, BenchmarkActor.BenchmarkResponse.class);
|
||||
} else {
|
||||
responseOpt = engineService.getAkkaTransporter().ask(url, request, BenchmarkActor.BenchmarkResponse.class);
|
||||
}
|
||||
final BenchmarkActor.BenchmarkResponse response = responseOpt.toCompletableFuture().get();
|
||||
if (BooleanUtils.isTrue(debug)) {
|
||||
log.info("[httpAsk] response: {}", response);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[httpAsk] process failed", e);
|
||||
ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import io.gatling.app.Gatling;
|
||||
import io.gatling.core.config.GatlingPropertiesBuilder;
|
||||
|
||||
/**
|
||||
* 压测启动入口
|
||||
* <a href="https://gatling.io/">压测启动入口</a>
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2023/1/8
|
||||
|
@ -6,7 +6,9 @@ import static io.gatling.javaapi.http.HttpDsl.*;
|
||||
import io.gatling.javaapi.core.*;
|
||||
import io.gatling.javaapi.http.*;
|
||||
/**
|
||||
* description
|
||||
* HTTP 压测模拟
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2023/1/8
|
||||
@ -24,12 +26,20 @@ public class HttpSimulation extends Simulation {
|
||||
|
||||
ScenarioBuilder scn = scenario("HttpSimulation") // 7
|
||||
.exec(http("request_http") // 请求名称,用于压测报表展示
|
||||
.get("/httpAsk?debug=true&responseSize=1024")) // 9
|
||||
.get("/pressure/ask?protocol=HTTP&debug=true&responseSize=1024")) // 9
|
||||
.pause(5); // 10
|
||||
|
||||
/*
|
||||
atOnceUsers(10) 一次模拟的用户数量(10)
|
||||
nothingFor(4 seconds) 在指定的时间段(4 seconds)内什么都不干
|
||||
constantUsersPerSec(10) during(20 seconds) 以固定的速度模拟用户,指定每秒模拟的用户数(10),指定模拟测试时间长度(20 seconds)
|
||||
rampUsersPerSec(10) to (20) during(20 seconds) 在指定的时间(20 seconds)内,使每秒模拟的用户从数量1(10)逐渐增加到数量2(20),速度匀速
|
||||
heavisideUsers(100) over(10 seconds) 在指定的时间(10 seconds)内使用类似单位阶跃函数的方法逐渐增加模拟并发的用户,直到总数达到指定的数量(100).简单说就是每秒并发用户数递增
|
||||
*/
|
||||
|
||||
{
|
||||
setUp( // 11
|
||||
scn.injectOpen(atOnceUsers(1)) // 12
|
||||
scn.injectOpen(incrementUsersPerSec(10.0).times(2).eachLevelLasting(10)) // 12
|
||||
).protocols(httpProtocol); // 13
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,13 @@ public class AkkaTransporter implements Transporter {
|
||||
private static final Map<String, String> WORKER_PATH_MAP = Maps.newHashMap();
|
||||
|
||||
/*
|
||||
HandlerLocation#fullPath -> actorName
|
||||
Akka 使用 ActorName + 入参类型 寻址,因此只需要 rootPath
|
||||
HandlerLocation#rootPathName -> actorName
|
||||
*/
|
||||
static {
|
||||
SERVER_PATH_MAP.put("", "");
|
||||
SERVER_PATH_MAP.put("benchmark", "benchmark");
|
||||
|
||||
WORKER_PATH_MAP.put("", "");
|
||||
WORKER_PATH_MAP.put("benchmark", "benchmark");
|
||||
}
|
||||
|
||||
public AkkaTransporter(ServerType serverType, ActorSystem actorSystem) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user