Gatling scala 压测代码
Gatling scala代码
1.Gatling
https://gatling.io/gatling-frontline/demo/
2.编写了一个淘宝 staging 环境的代码
package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class Taobao extends Simulation {
val httpProtocol = http
.baseUrl("https://www.taobao.staging.com") // Here is the root for all relative URLs
val myheader=Map("Content-Type"->"application/json;charset=UTF-8",
"x-anonymous"->"true",
"x-client-id"->"f74f7d9c15cd4dbabe540e32abf0ec3a",
"Accept"->"*/*",
"Connection"->"keep-alive",
"User-Agent"->"PostmanRuntime/7.26.5"
)
val scn = scenario("setupActiveSession Name") // A scenario is a chain of requests and pauses
.exec(http("setupActiveSession request") // Here's an example of a POST request
.post("/v2/session")
.headers(myheader)
.body(
StringBody(
"""{"device": {"device_id": null,"id": null},"version": "apiTest","session_token": null}"""
))
)
setUp(
scn.inject(rampUsers(500) during (600 seconds))
//admins.inject(rampUsers(2) during (10 seconds))
).protocols(httpProtocol)
}
运行的效果