How to build your social media marketing strategy for 2019

Facebook was shrouded in controversy due to its algorithm changes and privacy concerns. Instagram finally came into its own by rolling out a whole slew of business features while also passing the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Load test with Locust

From their official documentation page:

From my point of view, Locust is an open source load testing tool and one of the many alternatives to Jmeter. It allows you to write tests in Python and its implementation is based on tasks.

To be able to write a test you will need to define a locust file, it’s just a regular python file. There are more examples in the docs, but here’s what mine looked like:

At a minimum, you simply need to define 2 classes:

Locust class represents one user that will perform the tasks written in the task set.

TaskSet class basically mimics the behavior of the users. A TaskSet is a collection of tasks and each task contains a particular API operation (GET, POST, ..).

For load testing you might want to make one of the requests execute more often than the others, Locust allows you to do it by defining the weight for each task.

Once the test is running, tasks will be picked randomly. In case you want to execute the tasks in order, you can use TaskSequence:

After the test is run, locust will start spawning users, each user does the following:

Let’s say I have this locustfile.py and configuration like this:

Number of users simulate: 10 / Hatch rate: 1

When you start the load test with this configuration, locust will spawn 1 new user for every second until it reaches to the total number of users to simulate (which is 10 in this case).

Simply run this command to start Locust, you can also pass in the host you want to test if you didn’t define it in Locust class

Now open your browser and go to localhost:8089, enter the number of users and the hatch rate to start the load testing.

After that, you will be able to see the result of the ongoing test:

Once you have reached the desired number of requests, you can stop Locust from the web interface. It also allows you to reset the stats or run a new test.

In addition to the Statistics, you can then look at the charts (2nd tab) or any failures/exceptions received (3rd, 4th tab) as well as download test results as CSV files (the last tab).

Basically, requests per second (throughput) indicates the number of transactions per second your application can handle. And response time is the amount of time from the moment that a user sends a request until the time that your application indicates that the request has completed.

In the graph above you can see the correlation between response times and throughput. The overall throughput tends to decrease as you increase the response time for an average transaction. The reason is that after sending the 1st request, locust needs to wait until the request to be completed/processed to send the 2nd request. So that it’s tricky to use Locust if you want to have a fixed throughput.

Add a comment

Related posts:

How to plan for spontaneity

Planning to not have plans might seem a bit strange, especially if your goal is to soak up as much of a place as possible in the little time that you have. But just like you’ve got to know the rules…

10 Heart Healthy Meals and Spices Recommended You Eat This Year

A well-known spice that can improve digestion, lower cholesterol, boost brain function and memory. Cinnamon comes from the bark of the aromatic evergreen tree. Ground cinnamon contains a distinct…

SEMISPHERES

Semispheres is an atmospheric parallel puzzle game developed by Vivid Helix. The player uses both analog sticks to control two characters in parallel worlds that often intertwine through portals. At…