Skip to main content
No Result Found
Get your setup working faster. Join our Discord for optimisation tips from elite testers. Join our DiscordJoin our Discord

Protocol load testing using Locust

Run a protocol load test on BrowserStack Load Testing

Prerequisites

  • BrowserStack Username and Access key. You can find these under your account profile.
  • An existing Locust script written in Python (for example, a locustfile.py).

Supported versions

BrowserStack runs your Locust load tests on the following versions:

Tool Recommended version
Locust 2.46.7
locust-plugins 5.0.3

Run a test

Based on your preferred method of performing load tests, use one of the following methods:

Create a new test

You can start a new test either from the Quick Start page or the Load Tests page on the Load testing dashboard.

On the dashboard, click Create Load Test.

Screenshot of load testing dashboard showing the run a new test button highlighted

Enter a Test Name for your load test, select API Only, and click Upload scripts

Dashboard showing test name field and type of load test to run

Upload scripts

Upload your Locust scripts.

Load Sources step with Upload Script selected, Locust chosen as the framework, and the Upload a Locust Script drop area

BrowserStack Load Testing supports two upload modes for Locust tests:

Single file

Upload a single Python file (for example, locustfile.py) that contains your Locust test. This option works well when your script has no external dependencies beyond the Locust library and uses only the Python standard library.

The script must:

  • Import from Locust (for example, from locust import HttpUser, task, between).
  • Define at least one user class that subclasses HttpUser, FastHttpUser, User, or GrpcUser.
Sample locustfile.py
locustfile.py

Filter tasks by tag

To run only the tasks you tagged with @tag, or to skip some of them, filter tasks by tag. You don’t need to change your script.

  1. Turn on Filter Locust tasks by tag.
  2. In Filter mode, select Include to run only the tasks with these tags, or Exclude to skip them.
  3. In Tags, enter one or more tag names separated by spaces, for example checkout login.
  4. Optional: To add another filter, for example, to exclude some tags while including others, click Add filter.

Include maps to the Locust --tags option, and Exclude maps to --exclude-tags.

Filter Locust tasks by tag turned on with Include mode and the tags checkout and login

Once you have verified the configuration, click Configure Load to move to the next step.

You can also run load tests using the sample scripts if you want to try out the feature before uploading your own files.

Configure the load

On the Load Configuration step, set how much load to generate. You can enter the load profile manually, or use the load your Locust project already defines.

Use your Locust script’s load configuration

Run the test with the load your Locust project already defines, instead of entering users and duration in BrowserStack. BrowserStack reads the load from the following sources, in this order:

  1. A LoadTestShape class in your main script.
  2. The users, spawn-rate, and run-time settings in your configuration file.

To use your script’s load configuration:

  1. Go to the Load Definition tab.
  2. Turn on Use Locust script load configuration.

The card shows the load that will run, for example, StepShape, 500 users, and 30m. The Load Profile fields are hidden while the toggle is on.

Load Definition tab with Use Locust script load configuration turned on, showing StepShape, 500 users, and 30m, with the load profile fields hidden

If your LoadTestShape class keeps returning users, or your configuration file doesn’t set run-time, the test runs until your plan’s maximum test duration. In this case, the card shows Runs until plan limit (N min).

For more information, see Run a load test using your script’s own configuration and thresholds.

Set the engine count

An engine is one machine that generates load. Each engine runs up to 1,000 virtual users (VUs).

  1. Go to the Advanced Settings tab.
  2. In Engine Count, enter a number from 1 to 10. If you use more than one load zone, the engine count must be equal to or greater than the number of load zones. To let BrowserStack calculate it, leave the field empty. The field then shows Auto (recommended).

Advanced Settings tab with Engine Count set to 2, splitting 500 VUs into about 250 VUs per engine

If your configuration file sets iterations, set it to a value equal to or greater than the engine count. Each engine runs at least one iteration. For example, iterations = 4 supports up to 4 engines.

For more information, see Set the engine count for a load test.

You can configure the following load parameters to customize your load test:

Run the test

After configuring your load parameters, click Run Test to start your load test.

For more information on analyzing your test results, refer to View protocol test results.

Unsupported Locust features

BrowserStack doesn’t support Locust distributed mode. The master, worker, and related settings are blocked. BrowserStack distributes the load across engines for you. To control how many engines run your test, set the engine count.

What’s next

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle