Build load test tool Locust 1.1 on Docker

Introduction

When developing a Web system, I think it is necessary to know in advance not only whether it behaves as expected, but also how much load it can withstand.

This time, I would like to build Locust, a load test tool, on Docker and try it first.

Features of Locust

environment

The client PC will be Windows 10 Pro.

Official documents, etc.

The official documents are as follows.

Locust Official Document Locust github

Construction procedure

    1. Install Docker Desktop Install Docker DeskTop from the following. https://www.docker.com/products/docker-desktop
  1. Get the docker-compose.yml file Create a folder in any location and download the docker-compose.yml file from the following. https://github.com/locustio/locust/tree/master/examples/docker-compose

Change the -H part of the master command to the page you want to test.

version: "3"
services:
  web:
    build:
      context: ./apache-php
    ports: 
      - 80:80
    privileged: true
    links:
      - db
    volumes:
      - "./lara-d/:/var/www/html"
      - "./apache-php/apache.conf:/etc/httpd/conf/httpd.conf"
    container_name: "apache-php"
version: '3'

services:
  master:
    image: locustio/locust
    ports:
     - "8089:8089"
    volumes:
      - ./:/mnt/locust
    command: -f /mnt/locust/locustfile.py --master -H http://master:8089
  
  worker:
    image: locustio/locust
    volumes:
      - ./:/mnt/locust
    command: -f /mnt/locust/locustfile.py --worker --master-host master
    1. Creating locustfile.py locustfile.py is a file that describes the scenario and should be placed in the same location as docker-compose.yml.

This time, we will create a script to make a simple HTTP request.

from locust import HttpUser, task, between

class MyUser(HttpUser):
    wait_time = between(5, 10)  #Specify the timing to launch user

    @task(1)
    def index(self):
        
        url = '/api/test.php' #Specify the place to apply the load
        params = {'id':'0001'} #Specify parameters as needed

        headers = {'x-api-key':'***********'} #Add header items as needed

        self.client.get(url=url,params=params,headers=headers) #Send GET request

Execution method

    1. Start Docker

Open a command prompt, change to the folder where you placed docker-compose.yml, and execute the following command.

docker-compose up -d

If you want to increase the number of workers and load them in parallel, specify them at startup. I think it's okay to write it in an yml file.

docker-compose up -d --scale worker=3
  1. parameter settings After starting Docker, display Locust in your browser. http://localhost:8089/

コメント 2020-08-31 115336.png

Enter the number of users and the speed at which the users will start up, and press Start to execute. (The host will be the one set in yml)

Recommended Posts

Build load test tool Locust 1.1 on Docker
Load test Websocket with Locust
docker build python based on alpine
Prepare a distributed load test environment with the Python load test tool Locust
Build CGI Server running on Python 3 on Docker
Build a LAMP environment on your local Docker
pykintone on Docker
How to build a Django (python) environment on docker
Easy build of C ++ code with CMake on Docker
Install docker on Fedora31
Various load test tools
Build TensorFlow on Windows
Build XGBoost on Windows
Install Docker on AWS
build Python on Ubuntu
OpneJDK8 build on CentOS7_x86_64
Install Python 3.6 on Docker
Introducing Kaggle's Docker Image on Windows to build an environment