<我的備忘錄>Gatling介面測試簡單使用

來源:互聯網
上載者:User

標籤:

Gatling 的介紹和JMeter的效能對比請參看新一代伺服器效能測試工具Gatling

這裡記錄自己簡單使用心得.

1.下載安裝

直接下載zip檔案到本地目錄,解壓目錄即可。Gatling最新版2.17下載   

檔案目錄如下

result:儲存產生結果

user-files:測試的scala 指令檔

2.本次測試採用的是一個Play rest 工程。Play rest 工程----helloplay  其中有多個介面需要同步測試(刪除,更新操作類同)

POST    /user                                      controllers.Application.insert     //插入資料介面GET     /user/all                                   controllers.Application.findAll    // 查詢介面所有GET    /user/:id                                    controllers.Application.findasync(id:Long)     //查詢接單條

編寫測試代碼,測試代碼放在$GATLING_HOME/user-files/simulations/computerdatabase 目錄下

本例簡單測試簡單代碼如下

package jiangimport io.gatling.core.Predef._import io.gatling.http.Predef._import scala.concurrent.duration._class jiang_9_17 extends  Simulation {    // 測試介面部分    // 1. 查詢    object Search {        val search  = exec(http("Home").get("/")).pause(1)                            .exec(http("GetAll").get("/user/all ")).pause(1)                            .exec(http("Query").get("/user/10")).pause(1)            }    // 2. 插入    object Edit {        val insert = exec(http("Insert").post("/user").body(StringBody("""{"name":"han"}""")).asJSON).pause(1)    }// 設定瀏覽器資訊    val httpConf = http    .baseURL("     .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")    .doNotTrackHeader("1")    .acceptLanguageHeader("zh-CN,zh;q=0.8,en;q=0.6")    .acceptEncodingHeader("gzip, deflate")    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")// 設定許可權    user只能查詢,admin可以查詢和插入資料  val users = scenario("Users").exec(Search.search) // regular users can‘t Insert  val admins = scenario("Admins").exec(Search.search, Edit.insert)  // 佈建要求次數 如下為在10s內 user 查詢執行1000次,admin 查詢和插入執行100次  setUp(    users.inject(rampUsers(1000) over (10 seconds)),    admins.inject(rampUsers(100) over (10 seconds))  ).protocols(httpConf)}

執行gatling指令碼 ./$GATLING_HOME/bin/gatling.sh

選擇本次需要執行的指令檔[6]jiang.jiang_9_17     //  package 下的jiang_9_17 檔案

下面兩步選擇預設就可以了

 然後可以看到執行完成結果

$GATLING_HOME/result  目錄下產生了本次測試的可視化結果

<如本例>用瀏覽器開啟index.html 檔案瀏覽詳細資料(圖一為總體,二為每個介面對應資訊)

由於此次測試資料庫為本地,查詢比較快.因此介面請求時間都比較短。

更多資料請參考官網Gatling.io



<我的備忘錄>Gatling介面測試簡單使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.