6

A-Tune 服务配置与解释

 2 years ago
source link: https://silasmichealson.github.io/2022/05/09/A-Tune%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE%E4%B8%8E%E8%A7%A3%E9%87%8A/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A-Tune 服务配置与解释

一.启动服务

1.配置网卡及磁盘

在安装时使用下指令安装则将检测的磁盘和网卡写入/etc/atuned/atuned.cnf文件中,可以在文件中修改disk和network选指定的磁盘和网卡

make collector-install
make install
CMAKE

2.启动A-Tune服务

sudo systemctl daemon-reload
sudo systemctl start atuned
sudo systemctl start atune-engine

查看atuned或者atuned-engine服务状态

sudo systemctl status atuned
sudo systemctl status atune-engine
FORTRAN

3.atune-adm 命令

atune-adm list列出系统支持的profile以及当前已激活的profile

atune-adm profile [name]激活对应策略

atune-adm analysis [options]在线静态调优,实时采集系统信息进行负载类型识别并自动优化

atune-adm tuning [OPTIONS] <PROJECT_YAML>离线动态调优,使用指定项目文件对所选参数进行动态空间的搜索找到当前环境配置下的最优解。

二.离线动态调优测例

以A-Tune/examples/tuning目录中对gcc编译器的优化为例。

1.准备环境

sh prepare.sh

2.下载stream.c 内存带宽测试程序

wget http://www.cs.virginia.edu/stream/FTP/Code/stream.c

atune-adm tuning --project gcc_compile --detail gcc_compile_client.yaml
结果

内存带宽提升121%,编译后的可以执行文件大小减小17%。

4.保存结果

atune-adm tuning --restore --project gcc_compile

三.A-Tune离线调优应用

  离线动态调优包含三个输入文件:client.yaml、server.yaml和benchmark。

  • client.yaml: 存放在客户端的文件,包含调优的评价指标等信息。
  • server.yaml: 存放在服务端的文件,包含调优的可调节参数等信息。
  • benchmark: 存放在客户端的文件,通过运行该文件以获取评价指标的具体数值。
    这里以gcc离线动态调优为例,说明这三个文件。

1.client.yaml

其中包含:

调优算法选择(line 2)
迭代次数(line 3)
随机迭代次数(line 4)
benchmark执行命令(line 6)
评价指标1相关信息(line 8 - 13)
评价指标2相关信息(line 14 - end)
另外,还可以在client.yaml中添加参数选择:

参数选择是在进行离线动态调优前执行的步骤,其目的是在进行离线动态调优前缩减参数空间,在给出的参数空间中选择出对性能影响最大的参数并进行调优。

实现方法是在client.yaml中添加如下参数:

feature_filter_engine: 参数选择算法
feature_filter_cycle: 参数选择轮数
feature_filter_iters: 参数选择的迭代次数
feature_filter_count: 每轮选择出的参数
split_count: 调优参数取值范围中均匀选取的参数个数

2.server.yaml

应用启动命令(line 3)
应用停止命令(line 4)
可调参数等内容(line 5 - end)

3.benchmark文件

benchmark文件用于在调优执行时,会根据client.yaml中提供的命令执行此文件。

执行优化并保存结果
执行优化:
atune-adm tuning --project <PROJECT_NAME> --detail <client.yaml>

保存结果:
atune-adm tuning --restore --project <PROJECT_NAME>

四.A-Tune使用

1.总体说明

atune-adm支持的命令可以通过 atune-adm help/--help/-h 查询。

使用方法中所有命令的使用举例都是在单机部署模式下,如果是在分布式部署模式下,需要指定服务器IP和端口号,例如:

atune-adm -a 192.168.3.196 -p 60001 list
define、update、undefine、collection、train、upgrade不支持远程执行。

2.查询负载类型

list:查询系统当前支持的profile,以及当前处于active状态的profile。

atune-adm list

3.分析负载类型并自优化

使用默认的模型进行应用识别,不进行自动优化

atune-adm analysis --characterization
使用默认的模型进行应用识别,并进行自动优化

atune-adm analysis
使用自训练的模型进行应用识别

atune-adm analysis --model /usr/libexec/atuned/analysis/models/new-model.m

4.自定义模型

A-Tune支持用户定义并学习新模型。定义新模型的操作流程如下:

​- 步骤 1 用define命令定义一个新应用的profile

​- 步骤 2 用collection命令收集应用对应的系统数据

​- 步骤 3 用train命令训练得到模型

4.1 define

添加用户自定义的应用场景,及对应的profile优化项。

atune-adm define <service_type> <application_name> <scenario_name><profile_path>
使用示例

  • 新增一个profile,service_type的名称为test_service,application_name的名称为test_app,scenario_name的名称为test_scenario,优化项的配置文件为example.conf。

atune-adm define test_service test_app test_scenario ./example.conf

4.2 collection

采集业务运行时系统的全局资源使用情况以及OS的各项状态信息,并将收集的结果保存到csv格式的输出文件中,作为模型训练的输入数据集。

atune-adm collection <OPTINOS*>*
使用示例

atune-adm collection --filename name --interval 5 --duration 1200 --output_path /home/data --disk sda --network eth0 --app_type test_type

4.3 train

使用采集的数据进行模型的训练。训练时至少采集两种应用类型的数据,否则训练会出错。

atune-adm train <OPTINOS*>*
使用示例

使用data目录下csv文件作为训练输入,生成的新模型new-model.m存在model目录下。

atune-adm train --data_path /home/data --output_file /usr/libexec/atuned/analysis/models/new-model.m

4.4 undefine

删除用户自定义的profile。

atune-adm undefine <profile*>*
使用示例

删除自定义的profile。

atune-adm undefine test_service-test_app-test_scenario

5. Profile相关操作

5.1 查询profile

查看对应的profile内容。

atune-adm info <profile*>*
使用示例

查看web-nginx-http-long-connection的profile内容:

atune-adm info web-nginx-http-long-connection

5.2 更新profile

将已有profile中原来的优化项更新为new.conf中的内容。

atune-adm update <profile*>* <profile_path*>*
使用示例

更新名为test_service-test_app-test_scenario的profile优化项为new.conf。

atune-adm update test_service-test_app-test_scenario ./new.conf

5.3 激活profile

功能描述:

手动激活profile,使其处于active状态。

atune-adm profile <profile>
使用示例

激活web-nginx-http-long-connection对应的profile配置。

atune-adm profile web-nginx-http-long-connection

5.4 回滚profile

功能描述:

回退当前的配置到系统的初始配置。

atune-adm rollback
使用示例

atune-adm rollback

6. 更新数据库

更新系统的数据库。

atune-adm upgrade <DB_FILE>
使用示例

数据库更新为new_sqlite.db。

atune-adm upgrade ./new_sqlite.db

7. 系统信息查询

检查系统当前的cpu、bios、os、网卡等信息。

atune-adm check
使用示例

atune-adm check

8.参数自调优

使用指定的项目文件对参数进行动态空间的搜索,找到当前环境配置下的最优解。

atune-adm tuning [OPTIONS] <PROJECT_YAML>
在运行命令前,确保以下条件已经满足:

服务端的yaml配置文件已经编辑完成并放置于 atuned服务下的
**/etc/atuned/tuning/**目录中

客户端的yaml配置文件已经编辑完成并放置于atuned客户端任意目录下

进行tuning调优

atune-adm tuning --project compress --detail compress_client.yaml
恢复tuning调优前的初始配置,compress为yaml文件中的项目名称

atune-adm tuning --restore --project compress

五. A-Tune实战

1.通过A-Tune优化压缩算法配置

执行以下命令进入压缩文件样本目录:

cd ~/A-Tune/examples/tuning/compress/
获取测试用例:

wget http://cs.fit.edu/~mmahoney/compression/enwik8.zip
执行如下命令,使用prepare.sh脚本解压缩enwik8.zip文件并进行一些参数设置,例如compress_client.yaml文件中time的权重为20,compress_ratio的权重为80,表明本次优化目标偏重压缩率:

sh prepare.sh enwik8.zip
运行结果如下图所示:

说明:使用prepare.sh脚本对enwik8.zip文件进行解压缩完毕,当前目录应存在6个文件及一个文件夹,各文件的功能注解如下:

  1. enwik8.zip为压缩文件样本,

  2. enwik8为enwik8.zip文件解压后的文件夹,

  3. prepare.sh为执行调优前的必要准备工作,具体信息可以通过vim命令进入查看,

  4. compress.py为本次调优的基准。compress.py文件通过bz2、zlib、gzip中的一种方式对enwik8文件进行压缩。compress.py文件的执行时间将作为调优的评价指标之一,即compress.py文件执行时间越短,调优效果越好,

  5. compress_client.yaml文件记录本次调优的评价指标,有time和compress_ratio两个评价指标,

  6. compress_server.yaml文件记录本次调优的可调节项,有compressLevel和compressMethod两个可调节项。

执行以下命令进行查看:
ls -la
文件列表如下图所示:

继续执行以下命令,查看压缩算法的基线性能:

python3 compress.py
查看压缩算法的基线性能输出结果,如下图所示:

说明:通过压缩时间和压缩比例两个维度来衡量,图中时间花费4.6s左右,压缩后文件体积缩小2.7倍左右。后续步骤会对压缩算法进行调优,目标是降低时间花费,并增大压缩前后文件大小的比例。

注意:压缩算法的基线性能可能会因为具体的运行环境而有所不同。

执行以下命令对compress.py文件进行备份:
cp compress.py{,.bak}
说明:在进行调优时,compress.py文件中的COMPRESS_LEVEL和COMPRESS_METHOD两个值(12、13行)将会作为可调节项发生变更,因此在调节前备份此文件,有利于进行调优后与调优前的参数对比。

执行以下命令(约【2分钟】),进行调优以找到最优配置:

atune-adm tuning --project compress --detail compress_client.yaml
最终结果如下图所示,其中1为调优性能及参数,2为基线性能:

以上调优结果反映在了参数compressLevel和compressMethod的设置上,执行以下命令对比调优前后的compress.py文件:

注意:对比结果可能会因为具体的运行环境而有所不同。

diff compress.py compress.py.bak
对比结果如下图所示,图中可看到调优前后compressLevel的值有所区别,调优前compressLevel的值为1,调优后则为6,说明本次性能调优通过改变compressLevel的值提高了压缩算法的性能:

说明:执行调优时的各项参数解释如下:

  1. 评价指标,存于compress_client.yaml文件中,通过评价指标可以直观的看出性能优劣。
  • time:enwik8文件夹压缩时间,时间越短则性能越好;

  • compress_ratio:enwik8文件夹压缩前后的size大小,比例越大则压缩后文件占内存空间越小,说明压缩效果越好。

  1. 可调节项,存于compress_server.yaml文件中,单看可调节项的变化无法判断性能优劣,而是在每次修改可调节项后查看评价指标,基于评价指标的变化判断性能有无增长。
  • compressLevel:压缩等级,是调优的可调节项之一,本次调优共设九个等级,对应数值1~9;

  • compressMethod——压缩方式,是调优的可调节项之一,本次调优共设三种压缩方式,分别为bz2、zlib、gzip。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK