Enable Dark Mode!
By: Mohd Ajmal M

Odoo Load Balancing using Locust

Technical Odoo 15

Locust is an easy-to-use performance testing tool or framework that is distributable, scalable, and easily scriptable. However, it makes it possible to ramp up a test simulating thousands of users quickly. It is mostly a command-line tool written in Python and open-source licensed under MIT license. We can define the user behavior in regular python code instead of being stuck in websites or any other systems.

Locust provides a neat and user-friendly web interface with three graphical representations for Total Request per second, Response Time (in milliseconds), and Number of Users in order to monitor the load testing. The Failures, Exceptions, and Current Ratio statistics logs are also available. Users can download the Request statistics, Failures, and Exceptions (in CSV formats) and even the overall Report can be generated.

Installing & Configuring Locust with Odoo

It is better to install Odoo Locust and other dependencies on a virtual environment.

Install Locust, Odoo Locust, and other dependencies

pip install locust OdooLocust odoo-client-lib

Create Odoo Load test with Locust

Here we are going to stress Odoo with two simple tasks.

A. Search and Read Partners

B. Search and Read Products

Now create a python file and place the code below in it. Here we are going to Load test using OdooLocustUser class.

from locust import task, between
from OdooLocust.OdooLocustUser import OdooLocustUser
class Seller(OdooLocustUser):
    wait_time = between(0.1, 10)
    host = ''
    database = "database_name"
    login = "login"
    password = "password"
    port = port
    protocol = "jsonrpc"
    def read_partners(self):
        customer_model = self.client.get_model('res.partner')
        customer_ids = cust_model.search([])
        customers = cust_model.read(cust_ids)
    def read_products(self):
        product_model = self.client.get_model('product.product')
        ids = prod_model.search([])
        products = prod_model.read(ids)


1. OdooLocustUser:

The OdooLocustUser class is inherited from Locust’s HttpUser class which gives each user a client attribute that can be used to make requests to targeted Odoo systems we want to load tests.

2. wait_time:

Introduce delays after each task execution for each user instance. If wait_time is not specified, the next class will be executed as soon as one finishes.

constant - for a fixed value of time

between - for a random time between min_wait and max_wait values.

3. @tasks:

Each method with the @task decorator will define a task for the user instances to execute. It takes an optional weight argument that specifies the task execution ratio. In the above example, the read_partners task will have twice the chance of being picked as the read_products task.

4. self.client:

Makes it possible to make HTTP calls that will be logged by Locust.

Run Load Test

Run the python file we just created by

locust -f file_name.py

While running the above command, we get some details on which port locust will run like below.


Now goto on any web browser, and we will have the Locust UI there.


On the interface, Locust needs three inputs to start stressing Odoo.

1. Number of users.

2. Spawn rate - Users started per second.

For example, If the number of users is 20 and the spawn rate is 4, and when we start the load test, the locust will spawn 4 users for every second until it fulfills the total number of users to stimulate, so after 5 seconds we will have a swarm of 20 simulated users.

3. Host - If we specify the host on Python code, it automatically will fill here; otherwise, we can add from UI also.

The load Test for the above example is given below.


In this way, we can Load test our Odoo databases using Locust.

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message