JMeter vs Locust, which do you prefer ?

26 - Sep - 2019 All   Developer   Integrations   QA  

JMeter- Need bit more Freedom? Here you go LOCUST !

Apache JMeter is a great tool and it’s very popular.

As per my vision, JMeter does not give us full freedom to do. Agree? What about Locust? Let’s see in this article as we’ll make a comparison between both.

What are the Limitations?

1. You cannot program the script

2. Limitation to executing a huge number of services  & APIs in a single machine

3. Auto-correlation plugin It is recommended to run a load test in non-GUI mode. All instances of JMeter should be closed while running a load test

4. If you are trying to copy an element, suppose a Regex Extractor, from a script open in one version of JMeter to a script open in another version, it will throw an error.

Here is the Magic in Locust:

Write user test scenarios in plain-old Python

No need for clunky UIs or bloated XML—just code as you normally would. Based on coroutines instead of callbacks, your code looks and behaves like normal, blocking Python code.

Distributed & Scalable – supports hundreds of thousands of users

Locust supports running load tests distributed over multiple machines. Being event-based, even one Locust node can handle thousands of users in a single process. Part of the reason behind this is that even if you simulate that many users, not all are actively hitting your system. Often, users are idle figuring out what to do next. Requests per second != a number of users online.

Web-based UI 

It has a neat HTML+JS user interface that shows relevant test details in real-time. And since the UI is web-based, it’s cross-platform and easily extendable.


Locust is small and very hackable and we intend to keep it that way. All heavy-lifting of evented I/O and coroutines are delegated to gevent. The brittleness of alternative testing tools was the reason we created it.

An interesting solution made from it:

Locust has been used to simulate millions of simultaneous users. Battlelog, the web app for the Battlefield games, is load tested using it, so one can really say Locust is Battletested !

Let’s try this:

Step one : Locust is available on PyPI and can be installed with pip.

for python 2.7

$ python -m pip install locustio

for Python 3:

python3 -m pip install locustio

If you want the bleeding edge version, you can use pip to install it directly from our Git repository. For example, to install the master branch using Python 3:

$ python3 -m pip install -e git://

to make sure you got in

locust --help

Lets do simple login function for your easiness

Assignment: Login function via Rest Services

from locust import HttpLocust, TaskSet, task 
from locust import clients
from locust.clients import HttpSession 
import requests
global BaseUrl 
class auth():
    BaseUrl = "https://[Your-server]"
    #Auth API's Definitions
    def login( self,userName,passWord):
        s = HttpSession("https://[Your-server]")
        response ="https://[Your-server]", {"username":userName, "password":passWord})
        return response

    def getLogUser( self,accress_token):
        s = HttpSession("https://[Your-server]")
        response = s.get("https://[Your-server]", headers={'access_token':accress_token})
        return response

These two services as you see

-Login request(Post) with the parameter Username and password

-Request(Get) to get profile information of the user

What we need next. send the parameter to this API and create some load 🙂

First, we need external data handling for the credentials. In my case, I kept.CSV file for store different credentials of the users. Let’s try to read and push the data to API’s

class runnerAgent(TaskSet):
    global json_data
    global accress_token
    global path
    global ccLogin
    global API_KEY
    global getAr
    global VarCD
    def Login(self):
        #Object from globle file 
        conf = config.config()
        path = conf.getLocation()
        #object from Admin Auth
        login = authAgent.authAgent()
        PWConbv = util.util()
        #radis Cache Initialization
        Rcache = redis.Redis(host='', port=6379, db=0)
        with open('//oadTestv0.1/globe/credentials.csv') as csv_file:
            csv_reader = csv.reader(csv_file, delimiter=',')
            for row in csv_reader:
                print(" Login Agent with Username--->"+row[0]+" Who has Password --->"+row[1])
                #login Request 
                print Loginresponse
       --> (*)  assert Loginresponse.status_code is 200, "Unexpected response code: " + Loginresponse.status_code
                json_data =json.loads(Loginresponse.text)
                accress_token =json_data['content']["access_token"] 
                ccLogin =json_data ['content']["ccLogin"]
                print agentID
                ObjectAgent =json.dumps({ "UserName":row[0],"PassWord":row[1],"ccLogin":ccLogin,"id":agentID,"accress_token":accress_token})
                API_KEY = conf.getAPI_key()
                print API_KEY
                if Loginresponse.status_code==200:
class LoginWithUniqueUsersTest(HttpLocust):
    task_set = runnerAgent

For initial try let’s not bother about the #radis cache or other JSON readings. Just try to assert response code — > (*)

Run the test: There are two methods you can run the test

-With GUI

$ locust -f locust_files/ --host=

You will the running port in your local machine :

Once you’ve started Locust using one of the above command lines, you should open up a browser and point it to (if you are running Locust locally). Then the greetings will be something like this:

A locust class represents one user (or a swarming locust if you will). Locust will spawn (hatch) one instance of the locust class for each user. There are a few attributes that a locust class should typically define.

You can check the real-time statistics too.

JMeter vs Locust


locust -f  --clients=02 --hatch-rate=01   --host=  --no-web 

The console will print the summary for you.


JMeter vs Locust



Share this

You may also like

21 - Dec - 2020 All   Customer Support   Developer   Integrations   QA   StartUp   Uncategorized  
22 - Nov - 2019 All   Developer   Integrations   QA  
16 - Sep - 2019 All   Developer   Integrations   StartUp