locust | Write scalable load tests in plain Python 🚗💨 | Performance Testing library
kandi X-RAY | locust Summary
kandi X-RAY | locust Summary
Locust is an easy to use, scriptable and scalable performance testing tool. You define the behaviour of your users in regular Python code, instead of being constrained by a UI or domain specific language that only pretends to be real code. This makes Locust infinitely expandable and very developer friendly. To get started right away, head over to the documentation.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Listener function
- Adds a worker node to the scheduler
- Initialize the worker nodes
- Distribute the number of users and active users
- Initialize new instances
- Send a request to locusts
- Return a dictionary containing the context
- Build URL
- Send request to remote server
- Initialize a new dispatch
- Save Locale configuration variables
- Work worker
- Create a web UI
- Run a single user
- Sets up the event listeners
- Create an Environment instance
- Creates a function that returns a function that listens to keys
- Parse a time span
- Returns a tuple of the number of active users
- Start the scheduler
- Worker thread
- Return an HTML report
- Called when a request is received
- Load a locustfile
- Update template arguments
- Configure logging
- Parse the locustfile option
locust Key Features
locust Examples and Code Snippets
class StagesShape(LoadTestShape):
"""
A simply load test shape class that has different user and spawn_rate at
different stages.
Keyword arguments:
stages -- A list of dicts, each representing a stage with the follo
set PYTHONPATH=%PYTHONPATH%:%CI_PROJECT_DIR%\src
src.win_perf_counters.main as wmi_counters
'django.request': {
'handlers': ['console'],
'level': 'DEBUG',
},
class ApiLoggerMiddleware(MiddlewareMixin):
TOO_BIG_FOR_LOG_BYTES = 2 * 1024
def __init__(self, get_response):
# The get_re
@events.init.add_listener
def quit_env_failure_message(environment, **_kwargs):
global ENV
ENV = environment
if isinstance(environment.runner, MasterRunner):
environment.runner.register_message('env_failure', quit_on_en
with self.client.request("POST", build_path, headers=self.headers, data=json.dumps(updated_payload.__dict__), catch_response=True) as response:
if response.status_code == 403:
response.success()
self.client.get("/blog?id=%i" % i, name="/blog?id=[id]")
test:
before_script:
- Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
- choco install python3 --version=$PYTHON_VERSION --yes --force --no-progress
- refreshenv
script:
- python -V
- python -m
class folder_enter_scalability_taskset(SequentialTaskSet):
def on_start(self):
self.tm = TransactionManager()
@task
def seedata_config(self):
seeddata = next(seeddata_reader)
self.client.username = seed
from locust import HttpUser, task, events
import requests
class User(HttpUser):
@task
def scenario_01(self):
self.client.get('/some_endpoint')
def backgroundloop():
while True:
import time
starttime =
self.environment.runner.quit()
from locust import events
from locust.runners import STATE_STOPPING, STATE_STOPPED, STATE_CLEANUP, WorkerRunner
def checker(environment):
while not environment.runner.state in [S
Community Discussions
Trending Discussions on locust
QUESTION
I'm pretty new to locust
and load testing, I need to write a load test that should be for a total of 30 users, these users should be added to the test step by step and 3 users per minute, and at a time of 30 users at the same time, the test should be running for 5 minutes.Is there any way that I can do this?
ANSWER
Answered 2022-Apr-02 at 08:58for this timing that's enough to add a LoadTestShape
class to locustfile.py
like below:
QUESTION
I was wondering if using Locust as a library is more efficent than the original way as you don't have to make system calls for a new process this way thus reducing the initial delay at startup. I need to run thousands of separate loadtests for my app so it does make a difference.
...ANSWER
Answered 2022-Mar-31 at 19:20Yes it is more efficient. Starting Python, parsing all the imported dependencies etc takes some time.
How much faster is anyones guess though, and running thousands of individual load tests is not something I’ve seen anyone do, so I think you’ll have to test it yourself.
But if you are adding/removing replicas between tests, wont that be slower than restarting Locust anyway?
You can also run Locust in GUI mode and trigger a test by just sending an HTTP request to the /swarm endpoint, that should not have any significantly bigger start up time than library use.
QUESTION
I am new for locust. I have a CSV file which records the requests rate. And I want to sent a specify number of requests to a website according to the CSV file, like 500 requests per seconds, how can I do this?
Please help me about this problem, Thanks
...ANSWER
Answered 2022-Mar-15 at 20:09Sounds like what would be best for you is a Custom Load Shape. You can specify in code how many users get spawned at any given time during your test. You could read the values from your CSV and then set the user count and spawn rate appropriately.
http://docs.locust.io/en/stable/custom-load-shape.html
EDIT:
A Custom Load Shape lets you control the spawned number of users in code, but if you want to ensure you're getting a certain amount of Requests Per Second (RPS), that's going to be up to how you write your code. The code your Locust users runs needs to be written in such a way that each user is only making one request. Then in your Locust User class, you set wait_time = constant(1)
or wait_time = constant_pacing(1)
, whichever behavior you want.
http://docs.locust.io/en/stable/api.html?highlight=wait_time#locust.wait_time.constant
You can see this sort of pattern in all of the code examples for custom shapes.
QUESTION
I have a web server whose REST API I want to load test. I use locust==2.5.1, python==3.8.2.
Locust Config:
- Users:3
- Spawn Rate: 3
ANSWER
Answered 2022-Feb-24 at 16:30If all you're looking to do is get 2 requests per second, I don't think that article is what you want at all.
What you want to do is write your task
so it only does your self.client.post()
call appropriately. Then in your Locustfile, you need to set a wait_time
(see the docs here) that will be used to limit the time between users starting and running your task. You probably want wait_time = constant_pacing(1)
. Then when you run Locust, give it 2 users and a spawn rate of 2. That will immediately start 2 users and only 2 users which will do your post
call, wait one second, then be replaced by 2 users who will make the call again, giving you a constant 2 requests per second.
QUESTION
In our Locust scripts, we have a standardized format that we follow with self.client.post. In this format, I'm unable to get this post request to work:
...ANSWER
Answered 2022-Mar-04 at 22:59First thing I'd try is put the full URL in the self.client.post
instead just the route. Do it just like you did for the requests.post
.
You can also get the final request info from the response object. Use that to compare what was actually sent.
QUESTION
I wondered if there is a standard way in locust to detect and warn about performance degradation between runs. E.g.
Suppose I have an endpoint GET /helloworld
that returns a json like:
{"message":"hello world"}
on run1 of the performance test suite, the response time was 1 second, but running the locust
command, now returns in 3 secs. In my contrived example, lets say 3 secs is an 'acceptable' response time, thus we don't want to fail the test. However, the performance of the endpoint has degraded and we want to warn about this. What is the best way to achieve this in locust?
I thought maybe to save the results in csv
after each run and do a comparison with the csv
produced by the current/last run, but is there an easier way to achieve this? Thanks!
ANSWER
Answered 2022-Jan-23 at 15:09Maybe locust-plugins’s —check-avg-response-time
fits your need? It logs a message and changes Locust’s process exit code.
Used like this:
locust -f locustfile_that_imports_locust_plugins.py --check-avg-response-time 50
QUESTION
so I was trying to load test a Kerberos authenticated endpoint using the below locustfile (details removed):
...ANSWER
Answered 2022-Feb-18 at 14:01Turns out I needed to add certs to the default cert file that's used by Python, which I found this using this other post. After doing that, the requests all passed authentication as expected!
QUESTION
In a script in gitlab I have the following statement:
locust || true
This is because I don't want gitlab CI to stop the execution of the stage if the locust
command fails with some exit code. But how can I nevertheless retrieve the exit code of the locust
statement
ANSWER
Answered 2022-Feb-17 at 16:11If you place the command in an if
statement instead of using || true
, failure will not cause the script to exit and you'll be able to save the exit code.
QUESTION
Asked a similar question before, but I marked it answered, and I have other information.
Here is the structure:
...ANSWER
Answered 2022-Feb-14 at 09:33Since you're doing
QUESTION
Question in short
I have migrated my project from Django 2.2 to Django 3.2, and now I want to start using the possibility for asynchronous views. I have created an async view, setup asgi configuration, and run gunicorn with a Uvicorn worker. When swarming this server with 10 users concurrently, they are served synchronously. What do I need to configure in order to serve 10 concurrent users an async view?
Question in detail
This is what I did so far in my local environment:
- I am working with Django 3.2.10 and Python 3.9.
- I have installed
gunicorn
anduvicorn
through pip - I have created an
asgi.py
file with the following contents
ANSWER
Answered 2022-Feb-06 at 21:43When running the gunicorn
command, you can try to add workers
parameter with using options -w
or --workers
.
It defaults to 1
as stated in the gunicorn documentation. You may want to try to increase that value.
Example usage:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install locust
You can use locust like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page