码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-11-20 13:33:27      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   使用   sp   for   

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

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

标签:style   blog   http   io   ar   color   使用   sp   for   

原文地址:http://www.cnblogs.com/rd-log/p/4103746.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!