Install Locust

Check that your Python is at least version 3.6 with python -V or pyhthon3 -V

Activate your virtual environment and install locust with

python -m pip install locust

Review 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

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

You can check where locust was installed in this environment with

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:

Smoke test

To verify the installation you need a trial run

To run the simplest test variant create a locustfile.py file 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 as locustfile.py and run 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

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: