模拟压力场景

    本文主要介绍如何使用 Chaosd 模拟压力场景。该功能通过使用 stress-ng 在主机上生成 CPU 或者内存压力,支持通过命令行模式或服务模式创建压力实验。

    本节介绍如何在命令行模式中创建压力实验。

    在创建压力实验前,可运行以下命令查看 Chaosd 支持的压力实验类型:

    输出如下所示:

    1. Usage:
    2. chaosd attack stress [command]
    3. Available Commands:
    4. cpu continuously stress CPU out
    5. mem continuously stress virtual memory out
    6. Flags:
    7. Global Flags:
    8. --log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'
    9. Use "chaosd attack stress [command] --help" for more information about a command.

    模拟 CPU 压力命令

    运行以下命令可查看模拟 CPU 压力场景支持的配置:

    1. chaosd attack stress cpu --help

    输出如下所示:

    1. Usage:
    2. chaosd attack stress cpu [options] [flags]
    3. Flags:
    4. -h, --help help for cpu
    5. -l, --load int Load specifies P percent loading per CPU worker. 0 is effectively a sleep (no load) and 100 is full loading. (default 10)
    6. -o, --options strings extend stress-ng options.
    7. -w, --workers int Workers specifies N workers to apply the stressor. (default 1)
    8. Global Flags:
    9. --log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

    模拟 CPU 压力相关配置说明

    模拟 CPU 压力示例

    输出如下所示:

    1. [2021/05/12 03:38:33.698 +00:00] [INFO] [stress.go:66] ["stressors normalize"] [arguments=" --cpu 2 --cpu-load 10"]
    2. Attack stress cpu successfully, uid: 4f33b2d4-aee6-43ca-9c43-0f12867e5c9c

    模拟内存压力场景

    模拟内存压力命令

    运行以下命令可查看模拟内存压力场景支持的配置:

    1. chaosd attack stress mem --help
    1. Usage:
    2. chaosd attack stress mem [options] [flags]
    3. Flags:
    4. -h, --help help for mem
    5. -o, --options strings extend stress-ng options.
    6. -s, --size string Size specifies N bytes consumed per vm worker, default is the total available memory. One can specify the size as % of total available memory or in units of B, KB/KiB, MB/MiB, GB/GiB, TB/TiB..
    7. -w, --workers int Workers specifies N workers to apply the stressor. (default 1)
    8. Global Flags:
    9. --log-level string the log level of chaosd, the value can be 'debug', 'info', 'warn' and 'error'

    模拟内存压力相关配置说明

    配置项配置缩写说明
    sizes指定每个 vm worker 占用内存的大小支持使用单位 B,KB/KiB,MB/MiB,GB/GiB,TB/TiB 来设置占用的内存大小。如果不设置,则默认占用所有可用的内存。
    workersw指定用于生成内存压力的 worker 数量int 类型,默认值为 1
    optionsostress-ng 的其他参数设置,一般情况下不需要配置string 类型,默认值为 “”

    模拟内存压力示例

    输出如下所示:

    1. [2021/05/12 03:37:19.643 +00:00] [INFO] [stress.go:66] ["stressors normalize"] [arguments=" --vm 2 --vm-keep --vm-bytes 100000000"]
    2. [2021/05/12 03:37:19.654 +00:00] [INFO] [stress.go:82] ["Start stress-ng process successfully"] [command="/usr/bin/stress-ng --vm 2 --vm-keep --vm-bytes 100000000"] [Pid=26799]
    3. Attack stress mem successfully, uid: c2bff2f5-3aac-4ace-b7a6-322946ae6f13

    在运行实验时,请注意保存实验的 uid 信息。在不需要模拟压力场景时,使用 recover 命令来结束 uid 对应的实验:

    输出如下所示:

    1. Recover c2bff2f5-3aac-4ace-b7a6-322946ae6f13 successfully

    使用服务模式创建压力实验

    (正在持续更新中)