8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gatling環境構築

Posted at

経緯

  • 対して詳しくもないけど負荷試験することになった
  • 知ってる負荷試験ツールはJMaterかGatlingくらい
  • xml書きたくないからScalaでかけるGatling採用(Scalaも大してかけないけど)
  • Localと攻撃サーバで構築変わるのめんどいのでDocker

構成

├── docker-compose.yaml
├── gatling
│   └── Dockerfile
├── nginx
│   └── default.conf
└── scenario
   ├── resources    シナリオで使うやつ置き場(user-passwordのCSVとか)
   └── simulations シナリオのClass用ディレクトリ

Gatling用環境

../gatling/Dockerfile
FROM openjdk:11
ENV LANG C.UTF-8

RUN apt-get update -y \
    && apt-get upgrade -y \
    && apt-get install -y wget bsdtar

RUN mkdir /workdir && cd /workdir
WORKDIR /workdir

RUN wget -qO- https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.3.1/gatling-charts-highcharts-bundle-3.3.1-bundle.zip \
    | bsdtar -xvf-
ENV GATLING_HOME=/workdir/gatling-charts-highcharts-bundle-3.3.1
RUN ln -s /workdir/gatling-charts-highcharts-bundle-3.3.1/bin/gatling.sh /usr/local/bin/gatling && chmod a+x /usr/local/bin/gatling

docker-compose

  • gatling~/user-fileがシナリオ置き場なのでHostにvolumeMount
  • 結果のHTMLをnginxにMountする
  • とりあえず入力待ちにしとく
  • そのうち立ち上げたら勝手にシナリオ走るように
../docker-compose.yaml
version: "3"
services:
  gatling:
    build: ./gatling
    stdin_open: true
    tty: true
    volumes:
      - ./scenario/:/workdir/gatling-charts-highcharts-bundle-3.3.1/user-files
      - data:/workdir/gatling-charts-highcharts-bundle-3.3.1/results
    command: /bin/sh

  nginx:
    image: nginx:latest
    links:
      - gatling
    ports:
      - 80:80
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      - data:/var/html

volumes:
  data:
    external: true

結果確認用のNginx設定

  • マウント先をドキュメントルートに
  • 結果わかりやすくするため、autoindex
../nginx/default.conf
server {
    listen       80;
    server_name  localhost;
    autoindex on;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /var/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/html;
    }
}

実行(暫定)

  • gatling.shを動かせば対話形式で実行するシナリオを選べる

$ docker-compose up -d
$ docker-compose exec gatling gatling [-s TestClassName]
GATLING_HOME is set to /workdir/gatling-charts-highcharts-bundle-3.3.1
TestCodelikeAccess is the only simulation, executing it.
Select run description (optional)

Simulation TestCodelikeAccess started...
.
.
.
Reports generated in 0s.
Please open the following file: /workdir/gatling-charts-highcharts-bundle-3.3.1/results/testcodelikeaccess-20191212105057322/index.html

結果確認

8
8
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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?