Recently my team and I were tasked with improving the performance of some new complex web applications. Each web app had very speific flows that could change per user. We needed some benchmark numbers, and attempted to use jmeter. It sort of worked, but we found it lacking in some very specific scenarios. That’s when I discovered the wonderful world of locust.

Why Locust?

Locust is a simple and flexible load testing tool written in python. Locust hooked me with it’s hackability, all tests are written in python allowing you to define tests without entering a gui hell. When I paired locust with pyquery I found that I could create a performance test suite that worked against dynamic sites. The following is a simple example where if a user has a new message icon we make the rest call to retrieve it.

from pyquery import PyQuery as pq
from locust import HttpLocust, TaskSet

class UserBehavior(TaskSet):
    def testDynamicflow(self):
        loginResult ="/login", {"username":"chester", "password":"supersecure"})
        variableLength = pq(loginResult.text).find("#message")
        if (variableLength):
  "/app/viewMessage", {"username":"chester"})

class WebsiteUser(HttpLocust):
    task_set = UserBehavior

As you can see you pyquery is very similar to the popular jquery javascript library. For the most part pyquery supports css selectors. The biggest caveat is if your site does client side rendering or manipulation you cannot use those elements as part of your query.