locust | Write scalable load tests in plain Python 🚗💨 | Performance Testing library

 by   locustio Python Version: 2.19.2.dev8 License: MIT

kandi X-RAY | locust Summary

kandi X-RAY | locust Summary

locust is a Python library typically used in Testing, Performance Testing applications. locust has no bugs, it has no vulnerabilities, it has a Permissive License and it has high support. However locust build file is not available. You can install using 'pip install locust' or download it from GitHub, PyPI.

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.

            kandi-support Support

              locust has a highly active ecosystem.
              It has 21512 star(s) with 2708 fork(s). There are 437 watchers for this library.
              There were 10 major release(s) in the last 6 months.
              There are 9 open issues and 1438 have been closed. On average issues are closed in 48 days. There are 1 open pull requests and 0 closed requests.
              It has a negative sentiment in the developer community.
              The latest version of locust is 2.19.2.dev8

            kandi-Quality Quality

              locust has 0 bugs and 0 code smells.

            kandi-Security Security

              locust has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              locust code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              locust is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              locust releases are available to install and integrate.
              Deployable package is available in PyPI.
              locust has no build file. You will be need to create the build yourself to build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              locust saves you 5061 person hours of effort in developing the same functionality from scratch.
              It has 17954 lines of code, 1322 functions and 115 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed locust and discovered the below as its top functions. This is intended to give you an instant insight into locust implemented functionality, and help decide if they suit your requirements.
            • 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
            Get all kandi verified functions for this library.

            locust Key Features

            No Key Features are available at this moment for locust.

            locust Examples and Code Snippets

            Custom rate for adding user to test process in locust
            Pythondot img1Lines of Code : 36dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            Python importing main() problem - module exists, works in PyCharm, Gitlab says not found
            Pythondot img2Lines of Code : 4dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            src.win_perf_counters.main as wmi_counters
            Uvicorn async workers are still working synchronously
            Pythondot img3Lines of Code : 105dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            'django.request': {
                'handlers': ['console'],
                'level': 'DEBUG',
            class ApiLoggerMiddleware(MiddlewareMixin):
                TOO_BIG_FOR_LOG_BYTES = 2 * 1024
                def __init__(self, get_response):
                    # The get_re
            What is the cleanest to completely exit a locust process if test prerequisites fail?
            Pythondot img4Lines of Code : 18dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            'Response' object has no attribute 'success' error in Locust
            Pythondot img5Lines of Code : 5dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                    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:
            Hide query param values from console logs and html reports in Locust
            Pythondot img6Lines of Code : 2dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            self.client.get("/blog?id=%i" % i, name="/blog?id=[id]")
            Using pywin32 in a GitLab CI YML file - getting error on pip install
            Pythondot img7Lines of Code : 14dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                - Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
                - choco install python3 --version=$PYTHON_VERSION --yes --force --no-progress
                - refreshenv
                - python -V
                - python -m
            Locust/Python: Splitting a tasks array with if conditions in a SequentialTaskSet
            Pythondot img8Lines of Code : 22dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            class folder_enter_scalability_taskset(SequentialTaskSet):
                def on_start(self):
           = TransactionManager()
                def seedata_config(self):
                    seeddata = next(seeddata_reader)
                    self.client.username = seed
            Locust report /stats/requests data to other user interface
            Pythondot img9Lines of Code : 22dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from locust import HttpUser, task, events
            import requests
            class User(HttpUser):
                def scenario_01(self):
            def backgroundloop():
                while True:
                    import time
                    starttime =
            How can I get locust to stop load testing based on response from another API?
            Pythondot img10Lines of Code : 20dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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


            Custom rate for adding user to test process in locust
            Asked 2022-Apr-02 at 08:58

            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?



            Answered 2022-Apr-02 at 08:58

            for this timing that's enough to add a LoadTestShape class to like below:



            Performance using Locust with a locustfile vs as a library
            Asked 2022-Mar-31 at 19:20

            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.



            Answered 2022-Mar-31 at 19:20

            Yes 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.



            How do I set a specify RPS in locust ? like 500 requests per seconds
            Asked 2022-Mar-15 at 20:09

            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



            Answered 2022-Mar-15 at 20:09

            Sounds 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.



            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.


            You can see this sort of pattern in all of the code examples for custom shapes.



            Using Gevent inside locust task increases exponentially
            Asked 2022-Mar-15 at 07:28

            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


            Answered 2022-Feb-24 at 16:30

            If 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 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.



            Locust POST Request working in one format and not another
            Asked 2022-Mar-04 at 22:59

            In our Locust scripts, we have a standardized format that we follow with In this format, I'm unable to get this post request to work:



            Answered 2022-Mar-04 at 22:59

            First thing I'd try is put the full URL in the instead just the route. Do it just like you did for the

            You can also get the final request info from the response object. Use that to compare what was actually sent.



            Measuring performance degradation between performance between runs
            Asked 2022-Feb-21 at 10:00

            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!



            Answered 2022-Jan-23 at 15:09

            Maybe 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 --check-avg-response-time 50




            Locust endpoint authentication failing unless another endpoint is also called
            Asked 2022-Feb-18 at 14:01

            so I was trying to load test a Kerberos authenticated endpoint using the below locustfile (details removed):



            Answered 2022-Feb-18 at 14:01

            Turns 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!



            Bash - how to retrieve exit status of first command in an 'or' statement
            Asked 2022-Feb-17 at 17:43

            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



            Answered 2022-Feb-17 at 16:11

            If 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.



            Python importing main() problem - module exists, works in PyCharm, Gitlab says not found
            Asked 2022-Feb-14 at 09:33

            Asked a similar question before, but I marked it answered, and I have other information.

            Here is the structure:



            Answered 2022-Feb-14 at 09:33


            Uvicorn async workers are still working synchronously
            Asked 2022-Feb-07 at 18:39

            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 and uvicorn through pip
            • I have created an file with the following contents


            Answered 2022-Feb-06 at 21:43

            When 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


            No vulnerabilities reported

            Install locust

            You can install using 'pip install locust' or download it from GitHub, PyPI.
            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.


            Website: locust.ioDocumentation: docs.locust.ioSupport/Questions: StackOverflowCode/issues: GitHubChat/discussion: Slack signup
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries