Gatling:开源压力测试框架之入门

Gatling是一款开源的压力测试工具,基于Scala, Akka and Netty。

  • 可录制测试脚本,也可以手动编写脚本,适合有编程经验的测试人员使用;
  • 支持测试用例的参数化,可以使用csv、json、jdbc、redis等多样的数据源;
  • 能够模拟各种并发场景;
  • 能够生成比较详细的测试报表。

示例脚本:

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class RecordedSimulation extends Simulation {

    val httpProtocol = http
        .baseURL("http://192.168.1.117/")
        .acceptHeader("""*/*""")
        .acceptEncodingHeader("""gzip, deflate""")
        .acceptLanguageHeader("""zh-CN""")
        .userAgentHeader("""Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)""")

    val headers_2 = Map("""Accept""" -> """text/html, application/xhtml+xml, */*""")

    val scn = scenario("RecordedSimulation")        
        .repeat(1){
        //.forever{
            feed(csv("large_files.csv").circular)
            .exec(http("request_"+"${id}")
                .get("${uri}")
                .headers(headers_2)
                //.check(status.is(200)))
                .check(status.in(200 to 399)))
            .pause(1)
        }

    setUp(
        scn.inject(atOnceUsers(1000))
    )
    .protocols(httpProtocol)
}

 

large_files.csv默认放在user-files/data/下面
文件内容:
id,uri
1,index.html
2,download/file.zip

posted on 2014-11-20 12:43  零一积流  阅读(975)  评论(0编辑  收藏  举报

导航