DEV Community

Michael Wahl
Michael Wahl

Posted on

1

Load Testing in Python with Locust.io

Once a Website, API, or App is developed, there is often a need to start testing performance. Another useful aspect of Load testing is to start building out operating cost models as you develop pricing for example.
Let's jump in and get started…
From a terminal: run
pip install locust
locust -f locust.py
loadtest % locust -f locust.py
[2021–01–06 09:58:29,316] mbp.lan/INFO/locust.main: Starting web interface at http://0.0.0.0:8089 (accepting connections from all network interfaces)
[2021–01–06 09:58:29,322] mbp.lan/INFO/locust.main: Starting Locust 2.5.1
Open a Web browser and visit this page
http://localhost:8089/
Start a new load test
Set the number of total users to simulate
Set the spawn rate
Set the host
Start swarming
Details on the file below — locust.py
import time
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 5)
@task
def index_page(self):
self.client.get(url=”/hello”)
@task
def slow_page(self):
self.client.get(url=”/testsite”)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more