Skip to main content

Locust loadgen

Locust loadgen fault simulates load generation on the target hosts for a specific chaos duration. This fault:

  • Slows down or makes the target host unavailable due to heavy load.
  • Checks the performance of the application or process running on the instance.

Locust Loadgen Chaos

Use cases

  • Locust loadgen fault determines the resilience of an application under heavy load.
  • It determines how quickly the target application recovers from such a failure.
note
  • Kubernetes > 1.17 is required to execute this fault.
  • The target host should be accessible.
  • Kubernetes configmap that contains the config.py file is required. This file is used as a locustfile to generate load in the CHAOS_NAMESPACE. Below is a sample configmap:
apiVersion: v1
kind: ConfigMap
metadata:
name: load
namespace: <CHAOS-NAMESPACE>
data:
config.py: |
import time
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(1, 5)
@task
def hello_world(self):
self.client.get("")
  • If you change the config.py file, ensure that you update the CONFIG_MAP_FILE environment variable in the chaos experiment with the new name.

Fault tunables

Mandatory fields

Variables Description Notes
HOST Name of the target host under chaos. Provide the name of target host ex: https://google.com. For more information, go to target host.

Optional fields

Variables Description Notes
TOTAL_CHAOS_DURATION Time taken to inject chaos into the target resource (in seconds). Defaults to 60s. For more information, go to duration of the chaos.
CHAOS_INTERVAL Time interval between two successive instance poweroffs (in seconds). Defaults to 60s. For more information, go to chaos interval.
USERS Peak number of concurrent Locust users causing the load. Defaults 30. For more information, go to number of users.
SPAWN_RATE Number of users spawned per second. Defaults 30. For more information, go to spawn rate.
REPLICA Number of helper pod replicas generating the load. Defaults to 1.
LOAD_IMAGE Image used in helper pod that contains the chaos injection logic. Defaults chaosnative/locust-loadgen:latest. For more information, go to custom load image.
LOAD_TYPE Used as a suffix in the load file name. Defaults to load.
RAMP_TIME Wait period before and after injecting chaos (in seconds). For example, 30s. For more information, go to ramp time.

Target host

It specifies the value of the target host. Tune it by using the HOST environment variable.

Use the following example to tune the target host:

# generate load on the target host
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: load-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: locust-loadgen-chaos
spec:
components:
env:
- name: HOST
value: 'https://www.google.com'

Number of users

It specifies the number of users or workers involved in the load generation. Tune it by using the USERS environment variable.

Use the following example to tune the number of users:

# provid number of users for loadgen
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: load-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: locust-loadgen-chaos
spec:
components:
env:
- name: USERS
value: '100'
- name: HOST
value: 'https://www.google.com'

Custom load image

It specifies the rate at which users are spawned per second. Tune it by using the LOAD_IMAGE environment variable.

Use the following example to tune the custom load image:

# provid a custom image for load generation
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: load-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: locust-loadgen-chaos
spec:
components:
env:
- name: LOAD_IMAGE
value: 'chaosnative/locust-loadgen:latest'

Spawn rate

It specifies the custom image name of the load generated. Tune it by using the SPAWN_RATE environment variable.

Use the following example to tune the spawn rate:

# provid number of spawn users at (users per second)
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: load-nginx
spec:
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: locust-loadgen-chaos
spec:
components:
env:
- name: SPAWN_RATE
value: '100'
- name: HOST
value: 'https://www.google.com'