-
Notifications
You must be signed in to change notification settings - Fork 3k
Add things that you ran into and solved here! Anyone with a GitHub account can contribute!
If you have questions about Locust that are not answered here, please check StackOverflow, or post your question there. This wiki is not for asking questions but for answering them :)
How do I...
See Installation
- Increase the number of users. In order to fully utilize your target system you may need a lot of simultaneous users, especially if each request takes a long time to complete.
- If response times are unexpectedly high and/or increasing as the number of users go up, then you have probably saturated the system you are testing and need to dig into why. This is not really a Locust problem, but here are some things you may want to check:
- resource utilization (e.g. CPU, memory & network. Check these metrics on the locust side as well)
- configuration (e.g. max threads for your web server)
- back end response times (e.g. DB)
- client side DNS performance/flood protection (Locust will normally make at least one DNS Request per User)
- If Locust prints a warning about high CPU usage on its side (
WARNING/root: CPU usage above 90%! ...
)
- Run Locust distributed to utilize multiple cores & multiple machines
- Try switching to FastHttpUser to reduce CPU usage
- Check to see that there are no strange/infinite loops in your code
- If you are using a custom client (not HttpUser or FastHttpUser), make sure any client library you are using is gevent-friendly, otherwise it will block the entire Python process (essentially limiting you to one user per worker)
Note: Hatch rate/ramp up does not change peak load, it only changes how fast you get there (people keep asking about this for some reason).
Resolve errors that occur during load (error 5xx, Connection aborted, Connection reset by peer, etc)
Check your server logs. If it works at low load then it is almost certainly not a Locust issue, but an issue with the system you are testing.
Call
self.client.cookies.clear()
at the end of your task.
Locust's client in
HttpUser
inherits from requests and the vast majority of parameters and methods for requests should just work with Locust. Check out the docs and Stack Overflow answers for requests first and then ask on Stack Overflow for additional Locust specific help if necessary.
Try using Transformer
If you use WSL on a Windows computer, then you need one extra step than the "docker run ..." command: copy your locusttest1.py to a folder in a Windows path on your WSL and mount that folder instead of your normal WSL folder:
$ mkdir /c/Users/[YOUR_Windows_USER]/Documents/Locust/
$ cp ~/path/to/locusttest1.py /c/Users/[YOUR_Windows_USER]/Documents/Locust/
$ docker run -p 8089:8089 -v /c/Users/[YOUR_Windows_USER]/Documents/Locust/:/mnt/locust locustio/locust:1.3.1 -f /mnt/locust/locusttest1.py
Prefix the the endpoint to all
@app.route
definitions inlocust/web.py
file & also change as follows (where/locust
is new endpoint)
app = Flask(__name__, static_url_path='/locust')
Change the entries of static content location in file
locust/templates/index.html
.
Eg: <link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.ico') }}" type="image/x-icon"/>
Locust only knows what you're doing when you tell it. There are Event Hooks that you use to tell Locust what's going on in your code. If you use Locust's HttpUser
and then use self.client
to make http calls, the proper events are normally fired for you automatically, making less work for you unless you want to override the default events.
If you use the plain User
or use HttpUser
and you're not using self.client
to make http calls, Locust will not fire events for you. You will have to fire events yourself. See the Locust docs for examples.
https://github.com/locustio/locust/issues/2328
Check the list of issues (a lot of questions/misunderstandings are filed as issues)