Personal tools

Contact Us 24/7 > 1 866.SIX FEET

Skip to content. | Skip to navigation

Home > Blog > Performance Testing with Locust


Performance Testing with Locust

written by Rob McBroom on Tuesday November 18, 2014
Comments | Filed under: ,

We recently had a need to load test a new web application, logoand just could not get Jmeter to do anything useful. As an alternative, I tried using Locust. After a couple of hours, and fewer than 60 lines of code, I had a (mostly) working test.

If you have a need to load test anything, and even a minimal understanding of Python, I highly recommend looking into Locust. Here’s a brief overview of how it works:


The official documentation has a good basic example, so I won’t repeat it here. At a minimum, you simply need to define two classes:

  • A subclass of Locust
  • A subclass of TaskSet

A task set is just a group of one or more tasks you’d like your simulated users to perform during the test. Tasks can be hard-coded, or created and added to the set on-the-fly.


While this venture was successful overall, there were a few small annoyances I should mention.

Stats Lost After Users Spawned

Locust will gather and display stats as it’s creating users, but as soon as it reaches your requested number, all the stats are reset and it starts gathering new ones. If you want to see how many users it takes to cause problems on your site, you need to sit and stare at the web interface as it ramps up or that information will be gone.

Doesn’t Get All Resources

Locust won’t request a URL unless you explicitly tell it to. A legitimate user with an actual web browser will most likely end up requesting several URLs when loading a page (for images, style sheets, and scripts). Keep this in mind when building your tests. If you want to simulate an actual “page view”, you’ll need to explicitly list all the URLs for various resources, or try to automate this with something like BeautifulSoup.

For example, this will attempt to extract the URL from any tag with a src attribute:

    resource_urls = set()
    soup = BeautifulSoup(response.text)
    for res in soup.find_all(src=True):
        url = res['src']

The good news is that if you use the TaskSet class’s built-in client to request a URL, it will automatically be included in the stats.

Testing Never Stops

That is, you can’t tell it how many hits each user should simulate. If you want a specific number, you’ll need to just stare at the web interface and stop the test when the total gets close to what you want.


Overall, Locust is a great tool to quickly test running applications under load. Another tool we like for automated unit testing is Jenkins. You can read our article on Jenkins, Humans vs. Robots: Testing for Quality.


Like what you've read? Be sure to sign up for our weekly Plone & Python How-To digests.
Posted by Louis Henry Nayegon on Feb 18, 2015 09:06 AM
Testing Never Stops Have you tried the -n switch?
Posted by Anders Aarvik on May 03, 2016 03:41 AM
Regarding the lost/reset stats after hatching: Pull request has been set to fix this with a --no-reset-stats parameter in the CLI.
Add comment

You can add a comment by filling out the form below. Plain text formatting.

Rob's Recent Posts:
Stupid ZMI Tricks (12/11/2014)
Performance Testing with Locust (11/18/2014)

Next Steps

Select a type of support:

Contact our sales team

First name:
Last name:
Phone Number:
Fight spam:
What is + ?
Call Us 1 866.SIX FEET