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.
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.
Prerequisites
- 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 theCHAOS_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.
Mandatory tunables
Tunable | 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 tunables
Tunable | Description | Notes |
---|---|---|
TOTAL_CHAOS_DURATION | Time taken to inject chaos into the target resource (in seconds). | Default: 60s. For more information, go to duration of the chaos. |
CHAOS_INTERVAL | Time interval between two successive instance poweroffs (in seconds). | Default: 60s. For more information, go to chaos interval. |
USERS | Peak number of concurrent Locust users causing the load. | Default: 30 . For more information, go to number of users. |
SPAWN_RATE | Number of users spawned per second. | Default: 30 . For more information, go to spawn rate. |
REPLICA | Number of helper pod replicas generating the load. | Default: 1 . |
LOAD_IMAGE | Image used in helper pod that contains the chaos injection logic. | Default: chaosnative/locust-loadgen:latest . For more information, go to custom load image. |
LOAD_TYPE | Used as a suffix in the load file name. | Default: to load . |
GRANT_TYPE | Used for OAuth 2.0 authentication process. | Supports client_credentials only. Used when client requests access to protected resources based on the client ID and client secret. |
NODE_NAMES | Comma-separated node names subject to chaos | For example, node1,node2,.. |
CONFIG_MAP_FILE | Path to the configuration file where you set locust logic parameters. | You can specify additional file using the --config flag. |
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.
The following YAML snippet illustrates the use of this environment variable:
# 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.
The following YAML snippet illustrates the use of this environment variable:
# 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.
The following YAML snippet illustrates the use of this environment variable:
# 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.
The following YAML snippet illustrates the use of this environment variable:
# 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'