Enable Dark Mode!
odoo-load-balancing-using-locust.png
By: Akhilesh NS

Odoo Load Balancing using Locust

Technical

Locust is an easy-to-use, distributed, fresh open-source performance framework written in Python. It is intended for load-testing websites (or other systems) and figuring about how many concurrent users a system can handle. It is based on the MIT license.  

Locust stress Odoo with maximum concurrent users. Locust has a neat and beautiful web interface enabling users to monitor the request failure rate (percentage) at different load levels. Also, it provides three basic graphical representations for Total Request per second, Response Time (ms) and Number of users. The failure exception logs are also available in locust UI. After finishing a test, the user can download CSV files for Request Statics, Response time Distribution and Exceptions. 

Configuration of Locust with Odoo

1. Install locust, Odoo Locust, and other dependencies :

It is better to run locust with python 2.7. Python 3 has some issues with the Odoo Locust package and its dependencies. 

pip install locustio OdooLocust openerp-client-lib

2. Create your test with locust


Here I am stressing odoo with two simple tasks.

A. Read Partner ID’s
B. Read Product ID’s

Here is the seller_taskset.py file

from locust import  TaskSet, task
from OdooLocust import OdooLocust
class SellerTaskSet(TaskSet):
“””All tasks are defined in each function”””
@task(10)
def read_partners(self):
cust_model = self.client.get_model('res.partner')
cust_ids = cust_model.search([])
prtns = cust_model.read(cust_ids)
@task(5)
def read_products(self):
prod_model = self.client.get_model('product.product')
ids = prod_model.search([])
prods = prod_model.read(ids)
class Seller(OdooLocust):
“””Server credentials are given gere”””
host = "127.0.0.1"
database = "test"
port = 8015
login = "admin"
password = "admin"
protocol = "jsonrpc"
user_id = -1
min_wait = 100
max_wait = 1000
weight = 3
task_set = SellerTaskSet
Note:
1) @task takes an optional weight argument that can be used to specify the task’s execution ratio. In the above example, task1 will be executed twice as much as task2
2) max_wait = 1000
Maximum weighting time between the execution of locust task
3) min_wait = 100
Minimum weighting time between the execution of locust task
4) TaskSet class defines the execution behavior of this locust
5) weight = 3
The probability of locust being chosen. The higher the weight, the greater is the chance of being chosen. 

3. Run seller_taskset.py file by


locust -f seller_taskset.py Seller

odoo-load-balancing-using-locust-1-cybrosys

Now got to 127.0.0.1:8089 on any web browser.

odoo-load-balancing-using-locust-1-cybrosys

In the above interface, locust needs two inputs to start stressing odoo.

1. Amount of users to simulate 
2. Hatch rate: how quickly want to spawn the users

Example:

"Number of users to simulate" = 30
"Hatch rate" (user spawned / second) = 3

When we start the load test with this configuration, locust will spawn 3 new users for every second until it fulfills the total number of users to simulate (which is 30 in this case). After 10 seconds, you will have a swarm of 30 simulated users.

To control the no. of request per second, you will need to set the max_wait accordingly. 

Locust test for the above example is given below.


odoo-load-balancing-using-locust-1-cybrosys

odoo-load-balancing-using-locust-1-cybrosys

odoo-load-balancing-using-locust-1-cybrosys

odoo-load-balancing-using-locust-1-cybrosys

odoo-load-balancing-using-locust-1-cybrosys

Odoo Blogs Odoo Development Tutorials Odoo Apps


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



3
Comments

Edo

Thanks for this guide. make sure to install OdooLocust==1.0.0 else you get class params error

27/09/2019

-

12:40AM

Joseph John

Heading states load balancing, but in the article now where mentioned about load balancer,

24/01/2019

-

12:12AM

MOHAMED lOTFY

How can you manage the cron jobs if using multi instance ?

03/08/2019

-

11:53PM



Leave a comment

 


whatsapp
location

Calicut

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

location

Kochi

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

location

Bangalore

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

Send Us A Message