Skip to main content
Version: 2.6.5

Simulate Stress Scenarios

StressChaos Introduction

Chaos Mesh provides StressChaos experiments to simulate stress scenarios inside containers. This document describes how to create StressChaos experiments and how to prepare the corresponding configuration file.

You can create experiments using either Chaos Dashboard or the YAML configuration files.

Create experiments using Chaos Dashboard

  1. Open Chaos Dashboard, and click NEW EXPERIMENT on the page to create a new experiment:

    Create Experiment
    Create Experiment

  2. In the Choose a Target area, choose STRESS TEST and fill out the experiment information. For specific configuration fields, refer to the description in [Configuration Description](#fields description).

    StressChaos Experiment
    StressChaos Experiment

  3. Fill out the experiment information, and specify the experiment scope and the scheduled experiment duration:

    Experiment Information
    Experiment Information

  4. Submit the experiment information.

Create experiments using the YAML file

  1. Write the experiment configuration to the YAML configuration file. In the following example, the memory-stress.yaml file is used.

    apiVersion: chaos-mesh.org/v1alpha1
    kind: StressChaos
    metadata:
    name: memory-stress-example
    namespace: chaos-mesh
    spec:
    mode: one
    selector:
    labelSelectors:
    'app': 'app1'
    stressors:
    memory:
    workers: 4
    size: '256MB'

    This experiment configuration will create a process in the selected container, continuously allocate and read and write in memory, occupying up to 256MB of memory.

  2. After the configuration file is prepared, use kubectl to create an experiment:

    kubectl apply -f memory-stress.yaml

Field description

The fields in the YAML configuration file are described in the following table:

ParameterTypeDescriptionDefault valueRequiredExample
durationstringSpecifies the duration of the experiment.NoneYes30s
stressorsStressorsSpecifies the stress of CPU or memoryNoneNo
stressngStressorsstringSpecifies the stres-ng parameter to reach richer stress injectionNoneNo--clone 2
modestringSpecifies the mode of the experiment. The mode options include one (selecting a random Pod), all (selecting all eligible Pods), fixed (selecting a specified number of eligible Pods), fixed-percent (selecting a specified percentage of Pods from the eligible Pods), and random-max-percent (selecting the maximum percentage of Pods from the eligible Pods).NoneYesone
valuestringProvides a parameter for the mode configuration, depending on mode.For example, when mode is set to fixed-percent, value specifies the percentage of Pods.NoneNo1
containerNames[]stringSpecifies the name of the container into which the fault is injected.NoneNo["nginx"]
selectorstructSpecifies the target Pod. For details, refer to Define the Scope of Chaos Experiments.NoneYes

Stressors

ParameterTypeDescriptionDefault valueRequiredExample
memoryMemoryStressorSpecifies the memory stressNoneNo
cpuCPUStressorSpecifies the CPU stressNoneNo
MemoryStressor
ParameterTypeDescriptionDefault valueRequiredExample
workersintSpecifies the number of threads that apply memory stressNo1
sizestringSpecifies the memory size to be occupied or a percentage of the total memory size. The final sum of the occupied memory size is size.No256MB / 25%
timestringSpecifies the time to reach the memory size. The growth model is a linear model.No10min
oomScoreAdjintSpecifies the oom_score_adj of the stress process.No-1000
note

To avoid the high CPU load caused by the read and write pressure from stress-ng, Chaos Mesh uses memStress to simulate memory stress. This is because memStress simulates memory stress by consuming actual memory instead of applying the read and write pressure to memory.

CPUStressor
ParameterTypeDescriptionDefault valueRequiredExample
workersintSpecifies the number of threads that apply CPU stressYes1
loadintSpecifies the percentage of CPU occupied. 0 means that no additional CPU is added, and 100 refers to full load. The final sum of CPU load is workers * load.No50