LoginSignup
34
33

More than 5 years have passed since last update.

初めてのGatling

Last updated at Posted at 2017-02-14

Gatlingとは

公式

負荷テストツールである。
制約がないのであれば下記の理由などによりJmeterよりおススメされている。

  • 軽量に動作する
  • スケールアウトする
  • スクリプト(Scala)でテストをつくることができる
  • xmlいらない

Gatlingの技術要素として

  • JVM
  • Scala
  • AsyncHttpClient

環境構築

  • JDK8以上

Windowsでは公式からzipをダウンロードする。

サンプルテスト

  1. インストール先ディレクトリに移動
  2. 【インストール先ディレクトリ】\bin\gatling.batを起動
  3. 以下のような画面が出るのでここでは1を選択してEnter
サンプルテスト
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

後に以下のような画面が表示されるが何も入力せずにEnter

サンプルテスト
Select simulation id (default is 'advancedsimulationstep01'). Accepted characters are a-z, A-Z, 0-9, - and _

後に以下のような画面が表示されるが何も入力せずにEnter

サンプルテスト
Select run description (optional)

※ちなみ3.4.5については

  • 3.どのスクリプトを実行するか
  • 4.選択したスクリプトのIDをデフォルト(ファイル名を全て小文字にしたもの)から変更するか
  • 5.シミュレーションに説明書きを追記するか

という意味。

  1. テスト実行後にレポートの出力先がコマンドライン上に表示されているのでそのindex.htmlファイルを開く。
  2. レポートを確認! レポートの見方などについては(http://kyon-mm.bitbucket.org/blog/html/2013/12/29/gatling_script.html)

実行したスクリプトの格納先

【インストール先ディレクトリ】\user-files\simulations\computerdatabase

自作ソース編

下記のスクリプトを作成

ApiSimulation
package computerdatabase
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class ApiSimulation extends Simulation {
  val httpConf = http
    .baseURL("http://localhost:8080") // Here is the root for all relative URLs
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .doNotTrackHeader("1")
    .acceptLanguageHeader("ja,en-US;q=0.7,en;q=0.3")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0")

  val scn = scenario("Sample")
    .exec(http("request_1")
      .get("/"))
    .pause(100 milliseconds)

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

最終行の出力Injectionの意味。

  • rampUsers(100) over(10 seconds): 10秒間に100回アクセス
  • rampUsersPerSec(1) to (100) during (60 seconds) : 60 秒間で 1〜100 までユーザ増やしてアクセス
  • constantUsersPerSec(10) during(60 seconds) : 1 秒間で 10 ユーザのアクセスを 60 秒キープ

ブラウザ操作記憶編

これを参考。

設定周り

以下のような設定が可能。

全体での設定

  • ユーザー数固定

負荷をかけるユーザー数を固定する。

  • ユーザー数増やす

負荷をかけるユーザー数を増やす。

  • 実施する時間

負荷をかけている時間を設定する。

  • 一度だけ実行するか否か

特定の処理(ログイン処理など)を1回だけ実行する。

処理ごとの設定

  • 処理を繰り返すか
  • 失敗したときに処理を中断するか
  • 指定した秒数間隔で実行するか(pauseとは違う)

Gatling関連参考

  1. 便利すぎる負荷試験テストツールGatlingの使い方~自力ソース編~(http://qiita.com/nii_yan/items/d7d0ea949abeab13aea7)
  2. Gatlingでぶっ放せ!(http://qiita.com/idzzy/items/adc2c2fca1b4d74d67c9)
  3. Scala初心者がぶっぱなして負荷テストをやってみました(http://shanon-tech.blogspot.jp/2015/10/scala-gatling.html)
  4. 負荷テストツール、Gatlingで遊んでみる(http://d.hatena.ne.jp/Kazuhira/20131228/1388225775)
  5. Gatlingを使用してみた(http://gosyujin.github.io/2016/07/30/gatling-helloworld/)
  6. Gatling の exec メソッド内の記述方法と、Sessionの扱い方のまとめ(http://qiita.com/pekpec/items/036dde64eff87c26d84d)
34
33
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
34
33