壓力測試工具gatling安裝和介紹

Gatling主要用於測量基於HTTP的服務器,比如Web應用程序,RESTful服務等。
1 優點:
1.gatling和其他壓力工具相比有個好處是放在同一內網環境下linux服務器上,這樣避免其他壓力使用辦公機使用共有網絡,網絡情況對壓力測試的影響。
2 生成比較詳細的壓力測試報告。
3 能夠更靈活的編寫壓力腳本。
4 可以jenkins集合,將壓力測試整合自動化持續集成中。
2 安裝:
下載地址: http://gatling.io/#/download
bin目錄下有2個腳本,gatling和recorder, gatling用來運行測試, recorder用來啓動錄製腳本的UI的(不推薦使用)。
conf目錄是關於Gatling自身的一些配置。
lib目錄是Gatling自身依賴的庫文件。
results目錄用來存放測試報告的。
user-files目錄是用來存放測試腳本的。

3 壓力腳本介紹:

package computerdatabase  

import io.gatling.core.Predef._  
import io.gatling.http.Predef._  
import scala.concurrent.duration._  

class BasicSimulation extends Simulation {  

  val httpConf = http  
    .baseURL("http://computer-database.gatling.io") // 設置請求的Host  
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // 設置請求header  
    .doNotTrackHeader("1")  
    .acceptLanguageHeader("en-US,en;q=0.5")  
    .acceptEncodingHeader("gzip, deflate")  
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")  

  val headers_10 = Map("Content-Type" -> "application/x-www-form-urlencoded") // Note the headers specific to a given request  

  val scn = scenario("Scenario Name") // A scenario is a chain of requests and pauses  

    .exec(http("request_2")  
      .get("/computers?f=macbook"))  
    .pause(2)  
    .exec(http("request_3")  
      .get("/computers/6"))  
    .exec(http("request_9")  
      .get("/computers/new"))  
    .pause(1)  
    .exec(http("request_10")   
      .post("/computers")  
      .headers(headers_10)  
      .formParam("name", "Beautiful Computer")   
      .formParam("introduced", "2012-05-30"  
      )  
      .formParam("discontinued", "")   
      .formParam("company", "37"))//請求格式  

  setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))  

4 運行:

[html] view plain copy
cd bin
sh gatling.sh

5 生成報告:
results在目錄下生成報告:
以下是報告中的兩個圖表,其他圖就不貼了
壓力測試工具gatling安裝和介紹

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章