Personal tools
Contact Us 24/7 > 1 866.SIX FEET
Sections

Skip to content. | Skip to navigation

Home > Blog > Performance Testing with Locust

Blog

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, Locust.io 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:

Overview

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.

Limitations

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']
        resource_urls.add(url)

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.

Conclusion

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?
Add comment

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

puzzle
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:
Email:
Phone Number:
Message:
Fight spam:
What is + ?
 
Call Us 1 866.SIX FEET
Sections