使用Gatling做Web压力测试
作者:SegmentFault 发布时间:[ 2017/2/6 11:53:12 ] 推荐标签:压力测试 WEB测试
然后在 MySimulation.scala 可以 import ,使用里面定义好的方法了:
import scala.concurrent.duration._
import scala.util.Random
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import Feeders._
class MySimulation extends Simulation {
val brownse = feed(randomOffsetFeeder)
.exec(
home
)
}
用户注入策略
<= 10: 一把注入
> 10: 每10秒注入10个用户
val injectStrategy =
if (USERS_COUNT > 10) {
splitUsers(USERS_COUNT) into(
rampUsers(10) over(5 seconds)
) separatedBy(10 seconds)
} else {
atOnceUsers(USERS_COUNT)
}
压测时间策略
= 0: 所有模拟用户不循环,执行完测试场景即退出
> 0: 所有模拟用户循环执行测试场景,直到达到指定时间
val scn = scenario("My test scenario")
.doIfOrElse(DURATION > 0) {
forever(
exec(steps)
)
} {
exec(steps)
}
val setup = setUp(
scn.inject(
injectStrategy
).protocols(httpProtocol)
)
if (DURATION > 0) {
setup.maxDuration(DURATION minutes)
}
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。

sales@spasvo.com