LoginSignup
1
0

More than 3 years have passed since last update.

負荷試験でlocustを使ってみる

Posted at

locustについて

試してみる

前提

  • Docker、docker-composeがインストール済み

環境構築

locustのコンテナと、試しに負荷をかけてみるコンテナを作ります。

docker-compose.yml
version: '3.7'

services:
  master:
    image: locustio/locust
    ports:
      - "8089:8089"
    volumes:
      - ./:/mnt/locust
    # 負荷をかける環境のドメインを指定する
    command: -f /mnt/locust/main.py -H http://test_web:80

  # お試し用の負荷をかけられるコンテナ
  test_web:
    image: httpd
    tty: true

テストシナリオ

テストシナリオを作ります。

main.py
from locust import HttpUser, task, constant_pacing

class StressTestUser(HttpUser):
    wait_time = constant_pacing(1)

    @task
    def top_page_access(self):
        # 負荷をかける対象のパスを指定する
        self.client.get("/")

ユーザクラスを作ります。ユーザクラスは1人のユーザーが行う行動をwait_timeやtaskなどで定義していきます。
https://docs.locust.io/en/stable/writing-a-locustfile.html#wait-time-attribute

起動

コンテナを起動します。

docker-compose up

実行

  1. http://localhost:8089 をブラウザで開く
  2. Number of total users to simulate に同時アクセスを行う最大ユーザ数を入力する
  3. Spawn rate にユーザ数の増加速度を入力する
  4. Start swarming をクリックする 1.png

テスト状況

テストを実行すると状況が確認できます。
2.png
3.png

1
0
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
1
0