Serial and Parallel Experiments

    • If you want to schedule multiple chaos experiments in sequence, use serial nodes.
    • If you want to perform multiple chaos experiments simultaneously, use parallel nodes.

    Chaos Mesh uses composite pattern when designing serial and parallel nodes. It can contain multiple nodes of different types and run the composite nodes in a specific mode. This also means that you can nest the serial and parallel nodes to achieve complicated scheduling.

    When you create in Workflow, use templateType: Serial to claim a serial node.

    Another required field in serial nodes is children. Its type is []string and value is the name of other template. For example:

    When Chaos Mesh executes the serial node, tasks claimed in children are run sequentially to ensure that only one task is running at the same time.

    The deadline field in serial nodes is optional to limit the maximum duration of the entire serial process. Once this duration is running out, the sub-nodes are stopped and the nodes that are not executed yet will not be executed. If all sub-nodes finish their work before deadline time, serial nodes are immediately marked as completed and deadline is not affected.

    Parallel experiments

    When you create templates in Workflow, use templateType: Parallel to claim a parallel node.

    1. apiVersion: chaos-mesh.org/v1alpha1
    2. kind: Workflow
    3. metadata:
    4. spec:
    5. entry: parallel-of-2-chaos
    6. templates:
    7. - name: parallel-of-2-chaos
    8. templateType: Parallel
    9. deadline: 240s
    10. - workflow-stress-chaos
    11. - workflow-network-chaos
    12. - name: workflow-network-chaos
    13. templateType: NetworkChaos
    14. deadline: 20s
    15. networkChaos:
    16. direction: to
    17. action: delay
    18. mode: all
    19. selector:
    20. labelSelectors:
    21. 'app': 'hello-kubernetes'
    22. delay:
    23. jitter: '90ms'
    24. - name: workflow-stress-chaos
    25. templateType: StressChaos
    26. deadline: 20s
    27. stressChaos:
    28. mode: one
    29. selector:
    30. labelSelectors:
    31. 'app': 'hello-kubernetes'
    32. stressors:
    33. cpu:
    34. workers: 1
    35. load: 20
    36. options: ['--cpu 1', '--timeout 600']

    The above commands claimed a parallel node named parallel-of-2-chaos. This means Chaos Mesh executes simultaneously workflow-stress-chaos and workflow-network-chaos. After all tasks are completed, parallel nodes are marked as completed.

    When Chaos Mesh executes parallel nodes, all tasks claimed in children are executed simultaneously.

    Similar to serial nodes, the optional field deadline is also available in parallel nodes to limit the maximum execution time of the entire parallel process. If this time is reached, the sub-nodes are stopped. If all sub-nodes finish their work before time, parallel nodes are immediately marked as completed and deadline is not affected.