Load Testing with Locust.io

I’ve recently done some load testing using Locust.io. The setup was more complicated than other tools and I didn’t feel like it was well documented on their site. Here’s how I got Locust.io running on two different Linux platforms.

Locust.io on RedHat Enterprise Linux (RHEL) or CentOS

Naturally, these instructions will work on CentOS too.

sudo yum -y install python-setuptools python-devel
sudo yum -y install libevent libevent-devel

One requirement of Locust.io is ZeroMQ. I found instructions to install that on their site http://zeromq.org/distro:centos

sudo yum -y -c http://download.opensuse.org/repositories/home:/fengshuo:/zeromq/CentOS_CentOS-6/home:fengshuo:zeromq.repo install zeromq zeromq-devel
sudo easy_install locustio
sudo easy_install pyzmq

Locust.io on Debian or Ubuntu

sudo apt-get update
sudo apt-get -y install python-setuptools
sudo apt-get -y install python-dev
sudo apt-get -y install libevent-dev
sudo apt-get -y install libzmq3-dev
sudo apt-get -y install python-pip
sudo pip install locustio
sudo easy_install pyzmq

Running Locust.io Test

Here’s a simple python test script for Locust.io. Save this to a file named locust-example.py.

from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
    def index(self):
class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 1000
    max_wait = 3000

At this point you should be ready to run a test. You can run this from any user directory.

locust -H -f locust-example.py --master&
locust -f locust-example.py --slave&
locust -f locust-example.py --slave&
locust -f locust-example.py --slave&

The first line above specifies the host against which all requests will be executed, an IP address in this case. I start these as jobs that run in the background so I can start up some slaves too. In this case I start three. All the output from these will still go to stdout. You can verify that the processes are running using the jobs command.

debian@locust:~$ jobs
[1]   Running                 locust -H -f locust-testnginx.py --master &
[2]   Running                 locust -f locust-testnginx.py --slave &
[3]-  Running                 locust -f locust-testnginx.py --slave &
[4]+  Running                 locust -f locust-testnginx.py --slave &

You can now load the Locust.io user interface in a web browser. Just point to the hostname/IP on port 8089.


After starting up, Locust will spin up clients, distributed among the slaves, until it has reached the desired number. After it reaches the full number of clients it automatically resets the stats and keeps running until it is manually stopped.


That’s it. For better utilization of multiple cores, spin up additional slaves. I keep a locust.io image on hand so I can quickly spin it up when I have load testing to do. Since the test scripts are python, I keep them in the same repositories with the applications under test. Follow this link for full documentation for Locust.io.

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

About Daniel Watrous

I'm a Software & Electrical Engineer and online entrepreneur.

16 Responses to “Load Testing with Locust.io”

  1. Fatal error: Uncaught Error: Call to undefined function ereg() in /home/dwatrous/webapps/software_danielwatrous_com/wp-content/themes/headlines/includes/theme-comments.php:66 Stack trace: #0 /home/dwatrous/webapps/software_danielwatrous_com/wp-content/themes/headlines/includes/theme-comments.php(22): the_commenter_link() #1 /home/dwatrous/webapps/software_danielwatrous_com/wp-includes/class-walker-comment.php(180): custom_comment(Object(WP_Comment), Array, 1) #2 /home/dwatrous/webapps/software_danielwatrous_com/wp-includes/class-wp-walker.php(146): Walker_Comment->start_el('', Object(WP_Comment), 1, Array) #3 /home/dwatrous/webapps/software_danielwatrous_com/wp-includes/class-walker-comment.php(140): Walker->display_element(Object(WP_Comment), Array, '5', 0, Array, '') #4 /home/dwatrous/webapps/software_danielwatrous_com/wp-includes/class-wp-walker.php(371): Walker_Comment->display_element(Object(WP_Comment), Array, '5', 0, Array, '') #5 /home/dwatrous/webapps/software_danielwatrous_com/wp-includes/comment-template.php(20 in /home/dwatrous/webapps/software_danielwatrous_com/wp-content/themes/headlines/includes/theme-comments.php on line 66