Hadoop自动化测试--动态更新 hadoop xml 配置文件 篇

一、前言

需要测试 和 对比不同配置下的 performance,然后代码分析原因。这样会比较快找到 影响 performance 的配置。Hadoop 的 配置你知道的,多的不得了。如果不去想实现自动化,类似或者重复的劳动,人会变傻的。

二、 需要 解决的问题如下

1. 怎么更新、添加 和 删除一个xml 文件属性值?

用shell 语言:grep 正则表达式+sed 命令 替换。TMD 各种 特殊字符的处理,导致想换个路走。bing了一下网路发现有个工具 xmlstarlet  命令行处理 xml 文件不错。yum search xmlstarlet  没找到。

2. 想办法安装这个 xmlstarlet

找聊个rpm 包直接装吧 (refer to: https://cbs.centos.org/koji/buildinfo?buildID=7174)

wget http://cbs.centos.org/kojifiles/packages/xmlstarlet/1.6.1/1.el7/aarch64/xmlstarlet-1.6.1-1.el7.aarch64.rpm
wget http://cbs.centos.org/kojifiles/packages/xmlstarlet/1.6.1/1.el7/aarch64/xmlstarlet-debuginfo-1.6.1-1.el7.aarch64.rpm

安装需要 libxml2 和 libxslt2 库

sudo yum install libxslt

sudo yum install libxslt2
sudo rpm -ivh xmlstarlet-1.6.1-1.el7.aarch64.rpm

安装的路径查询:

rpm -ql xmlstarlet

3. 测试一把更新一个xml 的属性

就拿属性 <property><name>mapreduce.job.reduce.slowstart.completedmaps</name><value>0.6</value></property>来实验一把。

命令行输入:(给这神取了个新名,alias xml=xmlstarlet)

xml ed -u "//property[name='mapreduce.job.reduce.slowstart.completedmaps']/value" -v "0.8" ~/Hadoop/etc/hadoop/mapred-site.xml 
//添加 -L 参数,立即更新到目的文件。
xml ed -L -u "//property[name='mapreduce.job.reduce.slowstart.completedmaps']/value" -v "0.8" ~/Hadoop/etc/hadoop/mapred-site.xml 

注意:目前xmlstarlet 版本,如果找不到 xml 该属性,不会添加新的该属性,放弃该命令的执行。

~/Hadoop/etc/hadoop/mapred-site.xml 查看文件已经生效。

3. 获取HiBench 的report数据 和 jobhistory的网页数据,计算任务的平均耗时 和 mapred的每个阶段的平均耗时(Map/Merge/Shuffle/Reduce)

使用命令 elinks --dump 抓取 jobhistory的网页数据 输出到文件

while [ $i -lt $loop_num ]
do
       let "i++"
       #get the result of Average Map Time, Average Shuffle Time, Average Merge Time, Average Reduce Time
       echo "----------jobid=${job_id}_${i}---${property_name}=${property_value}-----------" >> $job_history_tmp_path
       elinks --dump "${job_history_path}job_${job_id}_000$i" | grep -o Average.*Time.* >> $job_history_tmp_path
       echo "----------jobid=${job_id}_${i}---${property_name}=${property_value}-----------" >> $job_history_tmp_path
done
 

输出每个任务的mapred的(Map/Merge/Shuffle/Reduce)耗时

function list_all_mapred_phases()
{
    cat  $job_history_tmp_path | awk 'BEGIN{record_num = 0} {if($4~/sec/) {split($4,sec,"sec");  a[$2]=sec[1]; record_num+=1 }
    else if($4~/min/) {split($4,min,"min"); split($5,sec,"sec"); a[$2]=min[1]*60+sec[1]; record_num+=1}
    {if(record_num==1) printf("%s\t%s\t%s\t%s\n", "Map","Shuffle","Merge","Reduce")}
    {if(a[$2]!="") printf("%.3f\t", a[$2])} {if($2==Reduce) printf("\n")} }' >> ${hibench_report_mapred_runtime_file}
    cat  ${hibench_report_mapred_runtime_file}
}
 

计算mapred的每个阶段的平均耗时(Map/Merge/Shuffle/Reduce):

function calculate_average_mapred_phases()
{
    echo "------------jobid=${job_id}-(1-to-${i})---${property_name}=${property_value}-----------" >>  ${hibench_report_mapred_runtime_file}
    cat  $job_history_tmp_path | awk 'BEGIN{record_num = 0} {if($4~/sec/) {split($4,sec,"sec");  a[$2]+=sec[1]; record_num+=1 }
    else if($4~/min/) {split($4,min,"min"); split($5,sec,"sec"); a[$2]+=min[1]*60+sec[1]; record_num+=1}}
    END{printf("%s\t %s\t %s\t %s\n", "Map","Shuffle","Merge","Reduce");
    printf("%.3f\t %.3f\t %.3f\t %.3f\n", a["Map"]*4/record_num, a["Shuffle"]*4/record_num, a["Merge"]*4/record_num, a["Reduce"]*4/record_num) }' >> ${hibench_report_mapred_runtime_file}
    echo "------------jobid=${job_id}-(1-to-${i})---${property_name}=${property_value}-----------" >>  ${hibench_report_mapred_runtime_file}
    cat ${hibench_report_mapred_runtime_file}
}

计算任务的平均耗时 :

function calculate_average_job_runtime()
{
    echo "----------${property_name}=${property_value}-----------" >> ${hibench_report_job_runtime_file}
    tail -${loop_num} ${hibench_report_file} | awk 'BEGIN{max = 0} BEGIN{min = 1999999} {printf("%.3f\t\t", $5)} {tot+=$5} {if ($5>max) max=$5 fi} {if ($5<min) min=$5 fi} END{printf( "\nAve:%.3f\t",tot/NR)} END{printf("Tot: %.3f\t",tot)} END{printf("Max: %.3f\t",max)} END{printf("Min: %.3f\t\n",min)}' >> ${hibench_report_job_runtime_file}
    echo "----------${property_name}=${property_value}-----------" >> ${hibench_report_job_runtime_file}
}
 

三、打通关节后,剩下的就是写脚本了

猜你喜欢

转载自blog.csdn.net/don_chiang709/article/details/81131482