Introduction to – Today we are going to introduce to you Locust is an open source performance testing tool. You develop your performance test scripts with Python. It allows you to distribute your performance test across different machine so you can create more load on your application under test.

Before deep dividing into Locust, in this article, we are going to show you how to install Locust, develop a simple test script and run it.

How to Install 

Prerequisite is to have Python 2.7 or 3.0 in your system. Then the only thing you should do is run below commands:

Python 2.7:

Python 3:

If everything is fine, you’ll be able to run locust command on terminal.

First Performance Test Script

You need to be familiar with Python to create test scripts. A locust class represents a single user. Locust will spawn one thread for each user that is being simulated. There are some attributes that you should be familiar with.

  • TaskSet: You should create a class with TaskSet is where you define the behavior of the user behavior. Then you define the action by @task annotation.

  • HttpLocust: In order to do HTTP calls, we need a class with HttpLocust parameter. Here, we define our test specific attributes like think times, etc. In that example, I define the min and max think the time that the system will wait before making any request. My requests will wait between 2 and 3 seconds. You also bind this configuration to your TaskSet. You may have different TaskSet and different Http configurations.

Here’s a sample script:

As you see, we are going to make 4 different GET requests to different endpoints during our load test. But the domain was not defined in the script. We can pass the HTTP domain while running the test from the command line with –host parameter or we can just add host variable in our class as shown below:

Execute the Script

To run your test, you should go to command line and navigate to the folder where you keep your script. Then, execute the below command by changing the file name.

In case you specified hostname in your class, don’t add –host parameter.

After executing the command, you’ll see below message on the command line.

Open a browser and navigate to http://localhost:8089

You will see a page which can be seen below. You need to set the maximum number of virtual users and Hatch Rate which means the ramp-up rate. Below configuration means that we’ll reach 100 users in 20 seconds.introduction to

Then, the test will start and you’ll see the results immediately.

In case you don’t want to deal with web UI, you can just run the below command to set virtual user configuration.

Then the results will appear on the console.locust

Save Results

To save execution results, just add –csv=result.csv to your terminal command. We did not extract any data or do the POST operation.

We’ll continue the Locust tutorials in next days with those examples.

May the performance be with you!