Better Programming

Advice for programmers.

Follow publication

Member-only story

Introduction To Locust: An Open-Source Load Testing Tool in Python

Ng Wai Foong
Better Programming
Published in
7 min readJan 3, 2020

Image source: the official Locust website

Fed up with the existing tools for benchmarking and load testing an existing server, I recently found an open-source tool called Locust to use in one of my projects.

By reading this piece, you’ll be able to use this load testing tool. This provides you with a rough idea of how much requests per second are (RPS) supported by your server. According to the official documentation, Locust is:

“… an easy-to-use, distributed, user load testing tool. It is intended for load-testing web sites (or other systems) and figuring out how many concurrent users a system can handle.

The idea is that during a test, a swarm of locusts will attack your website. The behavior of each locust (or test user if you will) is defined by you and the swarming process is monitored from a web UI in real-time. This will help you battle test and identify bottlenecks in your code before letting real users in.

Locust is completely event-based, and therefore it’s possible to support thousands of concurrent users on a single machine. In contrast to many other event-based apps it doesn’t use callbacks. Instead it uses light-weight processes, through gevent. Each locust swarming your site is actually running inside its own process (or greenlet, to be correct). This allows you to write very expressive scenarios in Python without complicating your code with callbacks.”

There are four sections in this tutorial:

  1. Setup
  2. Basic Usage
  3. Command Line Interface
  4. Conclusion

Let’s get started!

1. Setup

Installation is pretty straightforward as Locust is supported on 3.6, 3.7, and 3.8 (from version 0.14 onwards). You can simply run the appropriate pip command to install it based on your Python version. It is highly recommended to set up a virtual environment first.

Please be noted that locust has been renamed from locustio to just locust.

Python 3

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Ng Wai Foong
Ng Wai Foong

Written by Ng Wai Foong

Senior AI Engineer@Yoozoo | Content Writer #NLP #datascience #programming #machinelearning | Linkedin: https://www.linkedin.com/in/wai-foong-ng-694619185/

Responses (2)

Write a response