我正在使用 id "com.github.lkishalmi.gatling" 版本 "3.2.9" 来运行我的 gatling 性能测试
下面是我的模拟代码
print("TIME "+System.currentTimeMillis())
val httpConf = http.baseUrl("http://abc.io")
val httpConf2 = http.baseUrl(" http://abc.io")
val scenario_name = "only1_1in10"
val scn = scenario(scenario_name)
.exec(
http("370kb"+"_"+scenario_name)
.post("/pulse/swift/upload?startTime="+System.currentTimeMillis())
//.body(StringBody("""{ "runId": """" + 0 + """", "imageName":"""" + imageName + """" }""")).asJson
.bodyPart(RawFileBodyPart("file","src/gatling/simulations/370kb.png")).asMultipartForm
).exec(
http("370kb_next"+"_"+scenario_name)
.post("/pulse/swift/upload?startTime="+System.currentTimeMillis())
//.body(StringBody("""{ "runId": """" + 0 + """", "imageName":"""" + imageName + """" }""")).asJson
.bodyPart(RawFileBodyPart("file","src/gatling/simulations/370kb.png")).asMultipartForm
).exec(
http("370kb_next_next"+"_"+scenario_name)
.post("/pulse/swift/upload?startTime="+System.currentTimeMillis())
//.body(StringBody("""{ "runId": """" + 0 + """", "imageName":"""" + imageName + """" }""")).asJson
.bodyPart(RawFileBodyPart("file","src/gatling/simulations/370kb.png")).asMultipartForm
)
setUp(
scn.inject(
constantUsersPerSec(1) during (10)
)
).protocols(httpConf).assertions(forAll.failedRequests.percent.is(0))
我只是将图像上传到我的服务器。服务器反过来将这些图像推送到 kafka 队列并以 200 响应
我在第一个 http 组中的所有请求的问题总是很慢..而其他 http 组的速度更快。我知道第一个请求需要很长时间,因为服务器需要一些时间来预热。但是我很困惑为什么所有 10 个请求都很慢。
以下是上述代码相同图像的响应时间分布
有人可以解释为什么响应时间不断改善。第一组请求和后续组请求有什么区别?
我的服务器是一个简单的 Spring Boot 服务器,它接受多部分请求并将其推送到 Kafka 队列。
不同场景下分离后的代码
import io.gatling.http.Predef._
import io.gatling.core.Predef._
class OneSimulation extends Simulation {
print("TIME "+System.currentTimeMillis())
val httpConf = http.baseUrl("http://abc.io")
val httpConf2 = http.baseUrl(" http://abc.io")
val scenario_name = "only1_1in10"
val scn = scenario(scenario_name)
.exec(
http("370kb"+"_"+scenario_name)
.post("/pulse/swift/upload?startTime="+System.currentTimeMillis())
//.body(StringBody("""{ "runId": """" + 0 + """", "imageName":"""" + imageName + """" }""")).asJson
.bodyPart(RawFileBodyPart("file","src/gatling/simulations/370kb.png")).asMultipartForm
)
val scenario_name2 = "only1_1in10_2"
val scn2 = scenario(scenario_name2)
.exec(
http("370kb"+"_"+scenario_name2)
.post("/pulse/swift/upload?startTime="+System.currentTimeMillis())
//.body(StringBody("""{ "runId": """" + 0 + """", "imageName":"""" + imageName + """" }""")).asJson
.bodyPart(RawFileBodyPart("file","src/gatling/simulations/370kb.png")).asMultipartForm
)
val scenario_name3 = "only1_1in10_3"
val scn3 = scenario(scenario_name3)
.exec(
http("370kb"+"_"+scenario_name3)
.post("/pulse/swift/upload?startTime="+System.currentTimeMillis())
//.body(StringBody("""{ "runId": """" + 0 + """", "imageName":"""" + imageName + """" }""")).asJson
.bodyPart(RawFileBodyPart("file","src/gatling/simulations/370kb.png")).asMultipartForm
)
setUp(
scn.inject(
//atOnceUsers(20)
//rampUsers(10)during(10)
constantUsersPerSec(1) during (10)
//atOnceUsers(20),
),
scn2.inject(
//atOnceUsers(20)
//rampUsers(10)during(10)
constantUsersPerSec(1) during (10)
//atOnceUsers(20),
),
scn3.inject(
//atOnceUsers(20)
//rampUsers(10)during(10)
constantUsersPerSec(1) during (10)
//atOnceUsers(20),
)
//rampUsersPerSec(10) to(20) during(10) randomized)
).protocols(httpConf).assertions(forAll.failedRequests.percent.is(0))
}
在不同的场景中分开会给出相似的响应时间。然而,将所有请求放在相同的场景中,第一组的响应时间会变慢,但后续组的响应时间会更好。有人可以帮我解释一下这种行为吗