在使用训练和调优模式前,用户需要先导入benchmark所需数据并检查benchmark能否正常跑通,并备份好此时的数据库参数,查询当前数据库参数的SQL语句如下所示:
select name, setting from pg_settings;
训练模式和调优模式的过程类似,区别仅在于对配置文件的配置。X-Tuner模式使用的配置文件路径可以通过–help命令获取,代码如下所示:
...
-x TUNER_CONFIG_FILE, --tuner-config-file TUNER_CONFIG_FILE
This is the path of the core configuration file of the
X-Tuner. You can specify the path of the new
configuration file. The default path is /path/to/xtuner/xtuner.conf.
You can modify the configuration file to control the
tuning process.
...
通过help命令可以找到默认读取的配置文件路径,如果希望指定别的读取路径,则可以通过–x参数来完成。该配置文件的各个配置项的含义如表8-5所示。
表8-5 配置文件参数说明
| 参数名 | 参数说明 | 取值范围 |
| logfile | 生成的日志存放路径 | - |
| output_tuning_result | 可选,调优结果的保存路径 | - |
| verbose | 是否打印详情 | on,off |
| recorder_file | 调优中间信息的记录日志存放路径 | - |
| tune_strategy | 调优模式下采取哪种策略 | rl,gop,auto |
| drop_cache | 是否在每一个迭代轮次中进行drop cache,drop cache可以使benchmark跑分结果更加稳定。若启动该参数,则需要将登录的系统用户加入到/etc/sudoers列表中,同时为其增加NOPASSWD权限(由于该权限可能过高,建议临时启用该权限,调优结束后关闭) | on,off |
| used_mem_penalty_term | 数据库使用总内存的惩罚系数,用于防止通过无限量占用内存而换取的性能表现。该数值越大,惩罚力度越大 | 0 ~ 1 |
| rl_algorithm | 选择何种RL算法 | ddpg |
| rl_model_path | RL模型保存或读取路径,包括保存目录名与文件名前缀。在train模式下该路径用于保存模型,在tune模式下则用于读取模型文件 | - |
| rl_steps | RL算法迭代的步数 | - |
| max_episode_steps | 每个回合的最大迭代步数 | - |
| test_episode | 使用RL算法进行调优模式的回合数 | |
| gop_algorithm | 采取何种全局搜索算法 | bayes,pso,auto |
| max_iterations | 全局搜索算法的最大迭代轮次(并非确定数值,可能会根据实际情况多跑若干轮) | - |
| particle_nums | PSO算法下的粒子数量 | - |
| benchmark_script | 使用何种benchmark驱动脚本,该选项指定加载benchmark路径下同名文件,默认支持TPC-C、TPC-H等典型benchmark | tpcc,tpch,tpcds,sysbench… |
| benchmark_path | benchmark脚本的存储路径,若没有配置该选项,则使用benchmark驱动脚本中的配置 | - |
| benchmark_cmd | 启动benchmark脚本的命令,若没有配置该选项,则使用benchmark驱动脚本中的配置 | - |
| scenario | 用户指定的当前workload所属的类型 | tp,ap,htap |
| tuning_list | 准备调优的参数列表文件,可参考share/knobs.json.template文件 | - |
训练模式是用来训练深度强化学习模型的,与该模式有关的配置项有以下几个方面。
(1) rl_algorithm:用于训练强化学习模型的算法,当前支持设置为ddpg。
(2) rl_model_path:训练后生成的强化学习模型保存路径。
(3) rl_steps:训练过程的最大迭代步数。
(4) max_episode_steps:每个回合的最大步数。
(5) scenario:明确指定的workload类型,如果为auto则为自动判断。在不同模式下,推荐的调优参数列表也不一样。
(6) tuning_list:用户指定需要调哪些参数,如果不指定,则根据workload类型自动推荐应该调的参数列表。如需指定,则tuning_list表示调优列表文件的路径。调优列表配置文件的文件内容示例如下所示:
{
"work_mem": {
"default": 65536,
"min": 65536,
"max": 655360,
"type": "int",
"restart": false
},
"shared_buffers": {
"default": 32000,
"min": 16000,
"max": 64000,
"type": "int",
"restart": true
},
"random_page_cost": {
"default": 4.0,
"min": 1.0,
"max": 4.0,
"type": "float",
"restart": false
},
"enable_nestloop": {
"default": true,
"type": "bool",
"restart": false
}
}
待上述配置项配置完成后,可以通过下述命令启动训练:
gs_xtuner train -f connection.json
训练完成后,会在配置项rl_model_path指定的目录中生成模型文件。




