Created
January 21, 2024 21:45
-
-
Save thomaspaulb/4aa46d78cf4362a1259ef32cd87bafc4 to your computer and use it in GitHub Desktop.
test-rpc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from locust import HttpUser, task, between, events | |
import odoorpc | |
import logging | |
import time | |
import sys | |
``` | |
With this locust file, you can benchmark rpc calls of Odoo, eg load_views, fields_view_get, search etc. | |
NOTE: There is another Gist for testing page loads (test-pageload.py) | |
HOW TO USE | |
- save file as test-rpc.py | |
- modify variables | |
- pip install --user locust | |
- pip install --user odoorpc | |
- locust -H odoo.example.com -t 1min --headless -f test-rpc.py | |
``` | |
class WebsiteUser(HttpUser): | |
database = "mydatabase" | |
login = "myuser" | |
password = "mypassword" | |
port = 443 | |
protocol = "jsonrpcs" | |
wait_time = between(1, 2) | |
def on_start(self): | |
logging.info("Connecting to Odoo") | |
self.odoo = odoorpc.ODOO( | |
self.host, | |
port=self.port, | |
protocol='jsonrpc+ssl' | |
) | |
logging.info("Logging into Odoo") | |
self.odoo.login(self.database, self.login, self.password) | |
logging.info("Logged in! %s", self.odoo.env.user.login) | |
def load_views(self): | |
current_timestamp = int(round(time.time() * 1000)) | |
views = self.odoo.execute('sale.order', 'load_views', []) | |
sent_timestamp = int(round(time.time() * 1000)) | |
response_time = sent_timestamp - current_timestamp # milliseconds | |
events.request.fire(request_type="OdooRPC", name="load_views", response_time=response_time, response_length=sys.getsizeof(views)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment