7
7

More than 5 years have passed since last update.

GatlingでAPIに対して負荷テストをする方法

Last updated at Posted at 2016-02-10

これなんだ

負荷テストツール Gatling の使い方です。
http://gatling.io/#/

APIに対しての負荷テストをしてます。
request_1の結果の一部をrequest_2に投げてます。

インストール

$ wget https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/2.1.7/gatling-charts-highcharts-bundle-2.1.7-bundle.zip
$ unzip gatling-charts-highcharts-bundle-2.1.7-bundle.zip

シナリオを作る

これは20ユーザーがアクセスしてきます。
1ユーザーあたり2リクエストを送ります。
合計40リクエストが10秒間に来るアクセス数です。

user-files/simulations/computerdatabase/BasicSimulation.scala
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://hogehoge.mogemoge.fugafuga/")
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    .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")

  val scn = scenario("Scenario Name")
    .exec(http("request_1")
      .get("/v1/user/show/1")
      .check(jsonPath("$.user.groups[0].id").saveAs("mogemoge_groud_id")))
    .exec(http("request_2")
      .get("/v1/group/show/${mogemoge_group_id}")
      .check(status.is(404)))

  setUp(scn.inject(rampUsers(20) over(10 seconds)).protocols(httpConf))
}

実行

$ ./bin/gatling.sh
GATLING_HOME is set to ~~~~~~~~~~~~~~~~~~/gatling-charts-highcharts-bundle-2.1.7
Choose a simulation number:
     [0] computerdatabase.BasicSimulation
     [1] computerdatabase.advanced.AdvancedSimulationStep01
     [2] computerdatabase.advanced.AdvancedSimulationStep02
     [3] computerdatabase.advanced.AdvancedSimulationStep03
     [4] computerdatabase.advanced.AdvancedSimulationStep04
     [5] computerdatabase.advanced.AdvancedSimulationStep05
0 を選択
Select simulation id (default is 'basicsimulation'). Accepted characters are a-z, A-Z, 0-9, - and _
[Enter]
Select run description (optional)
[Enter]
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7