Installation Locust

Check that your Python is version 3.6 or higher with the command python -V or pyhthon3 -V

Activate your virtual environment and install locust with the command

pip install locust

Study the list of installed modules

python3 -m pip list

Package Version ---------- --------- Package Version ---------------- --------- certifi 2020.6.20 chardet 3.0.4 click 7.1.2 ConfigArgParse 1.2.3 Flask 1.1.2 Flask-BasicAuth 0.2.0 gevent 20.9.0 geventhttpclient 1.4.4 greenlet 0.4.17 idna 2.10 itsdangerous 1.1.0 Jinja2 2.11.2 locust 1.3.1 MarkupSafe 1.1.1 msgpack 1.0.0 pip 20.2.3 psutil 5.7.3 pyzmq 19.0.2 requests 2.24.0 setuptools 50.3.1 six 1.15.0 urllib3 1.25.11 Werkzeug 1.0.1 wheel 0.35.1 zope.event 4.5.0 zope.interface 5.1.2

locust pulls in a lot of dependencies, as you can see, even Flask is already here. Everything except pip, setuptools and wheel was installed together with locust.

You can check where locust was installed in this environment with the command

python -m pip show locust

Name: locust Version: 1.3.1 Summary: Developer friendly load testing framework Home-page: https://locust.io/ Author: None Author-email: None License: MIT Location: /home/andrei/python/virtualenvs/locust1_env/lib/python3.8/site-packages Requires: Flask-BasicAuth, msgpack, gevent, psutil, pyzmq, requests, ConfigArgParse, flask, geventhttpclient, Werkzeug Required-by:

Check that it works

To check the quality of the installation you need to do a trial run

To run the simplest version of the test, create the file locustfile.py and copy the following code into it ( source )

import time from locust import HttpUser, task, between class QuickstartUser(HttpUser): wait_time = between(1, 2) @task def index_page(self): self.client.get("/hello") self.client.get("/world") @task(3) def view_item(self): for item_id in range(10): self.client.get(f"/item?id={item_id}", name="/item") time.sleep(1) def on_start(self): self.client.post("/login", json={"username":"foo", "password":"bar"})

Go to the same directory where the locustfile.py file is located and run it with the command

locust

[2020-10-27 11:33:44,124] andrei-ubuntu/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces) [2020-10-27 11:33:44,133] andrei-ubuntu/INFO/locust.main: Starting Locust 1.3.1

If locust complains:

[2020-10-27 11:33:16,969] andrei-ubuntu/WARNING/locust.main: System open file limit '1024' is below minimum setting '10000'. It's not high enough for load testing, and the OS didn't allow locust to increase it by itself. See https://github.com/locustio/locust/wiki/Installation#increasing-maximum-number-of-open-files-limit for more info.

Read the solution here

Article author: Andrei Olegovich