Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locust : How to invoke the test through an API

I would like to invoke Locust load tests through an API to be able to start tests from a CI tool.

I dont see much documentation about such a scenario, there is no "Runner" or a similar class in the locust API documentation.

I checked the "locust" command which becomes available, after installation in Windows . It is a .exe so not sure what it does and how it actually starts the test

So , the specific question is, is there an interface to start the test from another Python program

like image 832
binithb Avatar asked Aug 21 '14 09:08

binithb


People also ask

How do you perform performance testing in API?

To run API performance tests well, you'll need to write multiple types of tests. The good news is that you can simplify this process by extending your API functional tests into API functional load tests, which provide the most nuanced level of insight into your API's overall performance.

How do I load a Python API test?

To start the load test, run locust -f locust_files/my_locust_file.py --host=http://example.com where host would be your IP. You can then go to 127.0. 0.1:8089 to select the number of virtual users to simulate. On windows there's a limitation of 1024 users only.


2 Answers

just do what you do in the locust web UI and do it in python.

if you monitor the network in the locust UI, you'll notice that invoking a swarm is just a GET request towards 127.0.0.1:8089/swarm with two arguments, locust_count and hatch_rate.

to answer your question, here's the api you asked for and example:

import requests

payload = {
'locust_count': 12,
'hatch_rate': 22,
}

res = requests.get('http://127.0.0.1:8089/swarm', params=payload)
print(res.json())

didn't test it, let me know if it doesn't work.

like image 107
timfeirg Avatar answered Oct 07 '22 18:10

timfeirg


Currently, there is no documented API for controlling locust, except for the command line interface. The CLI can be used to start running load tests, though currently one can't run locust distributed without the web UI.

You could also use the web UI as an API, and just make the HTTP requests, that the browser sends to the web UI, yourself from your program.

The locust.exe file that is created (by python's setuptools) in Windows, is just a small wrapper that will run main() in locust/main.py

like image 31
heyman Avatar answered Oct 07 '22 18:10

heyman