模拟 JVM 应用故障
Chaosd 可以通过 Byteman 模拟 JVM 应用故障,主要支持以下几种故障类型:
- 抛出自定义异常
- 触发垃圾回收
- 增加方法延迟
- 修改方法返回值
- 设置 Byteman 配置文件触发故障
- 增加 JVM 压力
同时,Chaosd 支持对常用的服务或其 Java 客户端注入上述的故障。比如,当 MySQL Java 客户端执行指定类型的 SQL 语句("select"
,"update"
,"insert"
,"replace"
或 "delete"
)时,你可以使用 Chaosd 在该客户端注入延迟或抛出异常。
本文主要介绍如何通过 Chaosd 创建以上故障类型的 JVM 实验。
使用命令行模式创建实验
本节介绍如何在命令行模式中创建 JVM 应用故障实验。
在创建磁盘故障实验前,可运行以下命令行查看 Chaosd 支持的 JVM 应用故障类型:
chaosd attack jvm -h
输出结果如下所示:
JVM attack related commands
Usage:
chaosd attack jvm [command]
Available Commands:
exception throw specified exception for specified method
gc trigger GC for JVM
latency inject latency to specified method
mysql inject fault into MySQL client
return return specified value for specified method
rule-file inject fault with configured byteman rule file
stress inject stress to JVM
Flags:
-h, --help help for jvm
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--uid string the experiment ID
Use "chaosd attack jvm [command] --help" for more information about a command.
使用命令行模式模拟抛出自定义异常
抛出自定义异常命令
运行以下命令查看抛出自定义异常场景支持的配置:
chaosd attack jvm exception --help
输出如下所示:
throw specified exception for specified method
Usage:
chaosd attack jvm exception [options] [flags]
Flags:
-c, --class string Java class name
--exception string the exception which needs to throw for action 'exception'
-h, --help help for exception
-m, --method string the method name in Java class
Global Flags:
--log-level string the log level of chaosd. The value can be 'debug', 'info', 'warn' and 'error'
--pid int the pid of Java process which needs to attach
--port int the port of agent server (default 9288)
--uid string the experiment ID
抛出自定义异常相关配置说明
配置项 | 配置缩写 | 说明 | 值 |
---|---|---|---|
class | c | Java 类的名称 | string 类型,必须配置 |
exception | 无 |