Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
Load TestingLocustPython

Python

Run a Python load test based on Locust on Linux VM or Kubernetes in Harness Resilience Testing

The Python Load Test Engine is based on Locust. It models user behavior as Python classes and tasks. Use Python when your team works in Python, when you want to express user journeys as code with conditional logic, or when you need a straightforward ramp-up to steady-state load. Python runs on both Linux VM and Kubernetes infrastructure, so it fits everything from a single on-premises host to scalable distributed runs.


What you can do with Python

You can do the following:

  • Reuse Python skills and scripts. Write scenarios as Python classes, or upload an existing .py Locust script.

  • Test from a single host. Run on a Linux VM for on-premises targets or direct network access to internal services.

  • Scale out on Kubernetes. Run a master pod with worker pods for higher concurrency.

  • Model user behavior. Weight tasks so frequent actions run more often than rare ones.


Prerequisites

  • Module access: Access to the Harness Resilience Testing module.

  • Infrastructure: A chaos infrastructure with load testing enabled, either a Linux Chaos Infrastructure or a Kubernetes Chaos Infrastructure (v1.85.3 or later).

  • Environment: An environment created in your project for the infrastructure.

  • An onboarded service: At least one service onboarded against that infrastructure.

  • Reachable target: Target application endpoints accessible from the test infrastructure.


Create a load test

Perform the following steps:

  1. Go to Resilience Testing > Load Testing.

  2. Click + New Load Test, then select Create from scratch.

TRY A SAMPLE TEST

Click + New Load Test and select Try Python-based Sample Test to explore the flow with a pre-configured test before you build your own.

Configure the load test overview

On the Overview tab, enter the test metadata, then select the infrastructure where the test runs. Set Name, an optional Description, and optional Tags, then choose a Target Type.

Select Linux VM as the target type, then select a Linux Chaos Infrastructure (with load testing enabled) from the Load Test Infrastructure dropdown. Set Load Test Engine to Python (Based on Locust).

The Harness chaos agent on the VM runs the Locust process locally and streams results back to Harness.

  • Best for simple setups, on-premises hosts, or direct network access to internal services.

  • Go to Linux Infrastructure for setup instructions.

Select Kubernetes as the target type, then select a Kubernetes Chaos Infrastructure from the Load Test Infrastructure dropdown. Set Load Test Engine to Python (Based on Locust).

The agent in the cluster orchestrates a master pod and optional worker pods for load generation.

  • Best for scalable, distributed load generation and cloud-native environments.

  • Go to Kubernetes Infrastructure for setup instructions.

Use lowercase letters, numbers, and dashes in Name. Harness derives the Id from it.

Select the services under test

A Services section appears once you choose an infrastructure, and it is required. Select at least one onboarded service under Resilience Testing Services. The picker lists only the services onboarded against the infrastructure you selected.

If that infrastructure has no onboarded services, the section reads No resilience testing services yet and offers Onboard a Service. You cannot continue until at least one exists, because Harness reports load results against the service rather than against the test alone.

Click Next to proceed to Test Configuration.

Define the test

On the Test Configuration tab, choose how you want to define the test workload. Locust supports two modes: upload a Python script, or reference a custom container image.

Upload a custom Locust .py script for advanced scenarios that require custom logic, authentication flows, or complex user behavior.

Field
Description

Host URL

Base URL of the application under test. Locust prepends this to all relative paths in your script.

Locust Script File

Drag and drop or browse to upload a .py file, up to 2 MB. You can also upload a .har browser recording, which Harness converts into a script.

@task(weight) controls relative execution frequency across tasks.

The Test Configuration tab with Upload Python script selected, showing the Host URL and Locust Script File upload fields alongside the Load Configuration and Load Profile graph

The Upload Python script mode. Provide an optional Host URL that Locust prepends to relative paths, upload your .py script, then set Users, Duration, Ramp Up Duration, and Worker Count in the Load Configuration.

Use a prebuilt container image as the load test source. This is useful when you have a custom Locust setup packaged as a Docker image. This mode is available on Kubernetes infrastructure only, since the image runs as a pod in the cluster.

Field
Description

Host URL

Base URL of the application under test.

Load Test Image

Container image reference (for example, my-registry/my-load-test:latest).

Entrypoint

Path to the Locust script inside the container (for example, /scripts/locustfile.py).

Arguments

Optional runtime arguments passed to the container (for example, tags=smoke,fast;headless=true).

Image Registry Type

Select Public for an image anyone can pull, or Private to pull with credentials.

Secret Name

The Kubernetes image pull secret used to authenticate. This field appears only when Image Registry Type is Private.

The Test Configuration tab with Using Custom Image selected, showing the Host URL, Load Test Image, Entrypoint, and Arguments fields alongside the Load Configuration and Load Profile graph

The Using Custom Image mode, available on Kubernetes only. Provide the Host URL, container image, entrypoint, and optional arguments, then set the load profile in the Load Configuration.

Configure the load profile

Configure how virtual users are ramped up and sustained during the test:

Parameter
Description
Constraint

Users

Peak concurrent virtual users.

Must be a positive integer.

Duration (seconds)

Total test runtime.

Must be greater than Ramp Up Duration.

Ramp Up Duration (seconds)

Time to reach peak users from zero.

Must be less than Duration.

Worker Count

Number of worker processes that generate load.

Must be a positive integer.

Steady-state duration = Duration - Ramp Up Duration.

DISTRIBUTED LOAD REQUIRES KUBERNETES

Only a Kubernetes target spreads load across workers, where each worker runs as its own pod. On a Linux VM the test runs as a single process on the host, so raising Worker Count does not distribute the load. Use a Kubernetes infrastructure when one host cannot generate enough traffic.

The Load Profile graph updates in real time as you adjust values, with a plain-English summary beneath it, for example Ramp up 100 users for 120s → maintain steady state for 480s.

Rather than guessing at a worker count, select Suggest beside Worker Count. Harness estimates the fleet it would take to drive the load you configured and reports the number, which resource limited the estimate, and how many users it expects to fit per worker. Expand Calculation to see the assumptions, then select Apply to write the number into the field. On a test that has never run, the estimate assumes default per-worker resources and a nominal request rate per user; run the test once and the next suggestion uses the measured rate instead.

Gate a release with pass/fail thresholds

Thresholds turn a load test into a gate. The Thresholds section is marked Optional (but recommended). Select + Add threshold to add a row, which Harness prefills with Response time (ms) / p95 / < / 5000.

Column
What to set

Metric

Response time (ms), Error rate (%), or Throughput (req/s).

Stat

The statistic to evaluate the metric on: p95, p99, avg, median, or max.

Operator

<, <=, >, or >=.

Value

The limit that must hold for the run to pass. This field carries a pin control, so the limit can be a runtime input.

Abort on Fail

Off by default. Turn it on to stop the run the moment the threshold is breached, rather than finishing and reporting the failure.

A breached threshold is marked failed in the run's Thresholds table, and the run still ends with Finished status and the code E3006: THRESHOLD_CROSSED. Turn on Abort on Fail to stop the run as soon as the threshold breaches. The run then ends with Stopped status and the code E3005: THRESHOLD_ABORT. Without thresholds a run still reports metrics, but nothing flags a performance regression.

Set a value at run time

Every tool input carries a pin control at the end of the field. Select it to switch the field between Fixed value and Runtime input.

A fixed value is stored with the test and used on every run. A runtime input leaves the field unset, so the value is supplied when the test runs, which lets one load test serve several environments or load levels. Go to Run a load test in a pipeline to supply these values from a pipeline.

Define variables

Variables is a drawer on the right edge of the Load Test Studio, available for both target types. A variable holds a value once and supplies it to the tool inputs, so a value such as a host name or a user count lives in one place instead of being repeated across fields.

Select + Add Variable and complete the New Variable dialog:

Field
Description

Type

String, Number, or Secret. Use Secret for credentials so the value is not stored in the test definition.

Name

The variable name.

Value

The value to use. This field carries its own pin control, so a variable can itself be a runtime input.

Description

(Optional) What the variable is for.

Select Save to add the row, then Apply Changes to keep the drawer's edits. The drawer lists each variable with its Variable, Description, and Value.

Tune pods with advanced options

Advanced Options is a drawer on the right edge of the Load Test Studio, available on the Test Configuration tab. What it contains depends on the target type, because the pod settings only apply where the test runs as pods.

Setting
Target
Default
What it does

Clean-up Load Resources

Kubernetes

On

Deletes the pods, configmaps, and secrets a run created once the run finishes. Turn it off to keep those resources for debugging, and remove them yourself afterwards.

Resource Requirements

Kubernetes

Off

Sets CPU and memory requests and limits on the load pods. Turn it on when a run is throttled or evicted, or when your cluster enforces quotas.

Environment Variables

Kubernetes and Linux VM

None

Passes configuration and secrets into the script without hardcoding them. Set SECRET to encrypt a value at rest.

Select Apply Changes to keep your edits, or Discard to close the drawer without saving.

Save and run the test

Perform the following steps:

  1. Click Save to create the load test. If Harness finds errors in the script, it does not save the test and lists the errors under the script. Go to Script validation to read and fix them.

  2. Find your test on the Load Tests tab, which lists each test with its Mode, Infrastructure, recent executions, and when it was last modified.

  3. Click the Run (▶) button on any test to start an execution.

  4. Monitor real-time results during execution.


Next steps

Last updated

Was this helpful?