TPC-DS工具介绍及性能测试

一. Hive-testbench 工具介绍

TPC-DS:https://www.cnblogs.com/webDepOfQWS/p/10544528.html

由于原生态工具生产测试数据表存在bug,后续引进hive-testbench,可参考:
https://bbs.huaweicloud.com/blogs/260840

可在WPS共享文档https://yundoc.fin-shine.com/drive/group/442074/3256599

或10.141.23.16 /home/appuser/hive-testbench下载 (配置项及脚本已修改)

1.1. 工具部署

执行tpcds-build.sh

(该工具需依赖包,执行后会提示,缺少什么安装什么依赖包)
一般需要这几个:yum -y install gcc gcc-c++

也可参考https://bbs.huaweicloud.com/blogs/260840

1.2. 脚本修改适配

修改脚本,直接使用hive(WSL环境没有配置beeline)
文件: tpcds-setup.sh

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| echo "TPC-DS text data generation complete." #HIVE="beeline -n hive -u 'jdbc:hive2://localhost:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2?tez.queue.name=default' "HIVE="hive" # Create the text/flat tables as external tables. These will be later be converted to ORCFile. |

修改不支持的参数,注释 hive.optimize.sort.dynamic.partition.threshold

vim settings/init.sql

vim settings/load-flat.sql

vim settings/load-partitioned.sql

-- set hive.optimize.sort.dynamic.partition.threshold=0;

(目前发现仅在Cloudera中提供该配置:
https://docs.cloudera.com/cdp-private-cloud-base/7.1.5/ozone-storing-data/topics/ozone-config-work-with-Hive.html)

1.3. 生成测试数据

例如# 生成大小100G的数据集# 生成文件放置于/tmp目录下

bash tpcds-setup.sh 100 /tmp/100

(可在HDFS上查看已生成的文件: sudo -u hdfs hadoop fs -du -h /tmp)

1.4. 执行99条SQL

路径:/hive-testbench-hdp3/sample-queries-tpcds

方法一:

执行hive命令进入数据库执行命令界面,然后执行:

hive> use tpcds_bin_partitioned_orc_100;

hive> source query12.sql;

方法二:

使用脚本批量执行,通过/tmp/tpcds_bin_partitioned_orc_100.Log查看所有执行SQL结果。

(/tmp/tpcds_calc.log便于统计每条SQL执行的耗时情况,实际以上述结果为准!)

命令:sh autoTpcDs.sh

脚本内容:(仅参考,根据实际内容修改)

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| #!/bin/bash base_dir='/home/appuser/hive-testbench/hive-testbench-hdp3/sample-queries-tpcds' DBbase=tpcds_bin_partitioned_orc_100 for sql_num in `seq 1 99` do if (({sql_num}==18));then continue 1 else echo "=============sql_num: query{sql_num} ==============" hive -e "use ${DBbase};source {base_dir}/query{sql_num}.sql" echo "=============sql_num: query{sql_num} ==============" \>\> /tmp/tpcds_calc.log grep 'Time taken' /tmp/{DBbase}.log|tail -1 >> /tmp/tpcds_calc.log 2>&1 fi done >> /tmp/${DBbase}.log 2>&1 |

二. TPC-DS

2.1. TPC-DS编译

yum install -y gcc gcc-c++ expect byacc flex bison

地址: git clone git@github.com:gregrahn/tpcds-kit.git

地址:git clone https://github.com/gregrahn/tpcds-kit.git

进入tool目录下

执行 make

2.2. 建表

在tools目录下 查看tpcds.sql文件,提供了基础的建表语句

2.3. 生成数据

2.3.1. 创建存放生成数据的目录

mkdir /root/tpcdsdata

2.3.2. 生成指定大小的数据到创建的目录

|--------------------------------------------------------------------------------------|
| ./tools/dsdgen -SCALE 100GB -DIR ./data_100G -SCALE:指定生成数据量大小如:100GB、200GB、1TB、100TB |

2.4. 根据模板生成查询语句

通过使用dsqgen命令根据TPC-DS提供的模板生成不同类型的SQL语句,TPC-DS默认支持以下模板:db2.tpl、netezza.tpl、oracle.tpl、sqlserver.tpl

|------------------------------------------------------------------------------------------------------------------------------------------------------|
| for i in `seq 1 99` do   ./dsqgen -DIRECTORY ../query_templates/ -TEMPLATE "query{i}.tpl" -DIALECT netezza -FILTER Y \> ../sql/query{i}.sql done |

-DIRECTORY:SQL模板的路径。 这个是查询模板的文件目录位置 .../query_templates/注意:因为query_templates只有99个查询模板,所以最多一次只能生成99个查询语句,但是如果生成多次,生成的99个查询语句是一样

-TEMPLATE:SQL模板的名称

-DIALECT:include query dialect defintions found in < s >.tpl 。-DIALECT postgresql 是哪种数据库的查询语句

注意:DIALECT支持oracle,db2,sqlserver,netezza,ansi,但是没有postgresql。可以去query_templates文件目录下看是否有对应的模板文件,推荐netezza,pg可以解析。

-FILTER:重定向到标准输出,即.../sql/query${i}.sql 是输出路径和文件类型。

2.5. 所有表分别导入数据

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 举例:psql -h 172.0.0.1 -p 31000 -U zhouwh -d testdb_100g -c "\COPY catalog_returns FROM '/home/appuser/tpcds-kit/data_100g/catalog_returns.dat' with DELIMITER as '|' NULL '' SEGMENT REJECT LIMIT 10000 ROWS;" |

脚本:

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| #数据库名称 DB=testdb_100g #dat文件路径 addr='/home/appuser/tpcds-kit/data_100g' now=`date +%Y%m%d%H%M%S` cd addr #编辑文件 total_cost1=0 for i in \`ls \*.dat\|cut -d '.' -f 1\` do echo "###{i}开始编辑dat文件..." begin_time1=`date +%s.%N` sed -i -r 's/(.)$//g' {addr}/{i}.dat rcsed=? end_time1=\`date +%s.%N\` cost1=\`echo "end_time-begin_time"\|bc\` total_cost1=\`echo "total_cost+$cost"|bc` if [ $rcsed -ne 0 ] ; then printf "###!%s编辑失败\n" $i else printf "###%s编辑成功!cost耗时::%.2f秒,累计耗时::%.2f秒\n" $i $cost1 total_cost1 fi done #导入数据 total_cost=0 for i in \`ls \*.dat\|cut -d '.' -f 1\` do echo "{i}开始导入数据..." begin_time=`date +%s.%N` psql -h 172.0.0.1 -p 31000 -U zhouwh -d ${DB} -c "\COPY {i} FROM '{addr}/{i}.dat' with DELIMITER as '\|' NULL '';" 2\>/tmp/null rc=? end_time=`date +%s.%N` cost=`echo "end_time-begin_time"|bc` total_cost=`echo "total_cost+cost"|bc` if [ $rc -ne 0 ] ; then printf "#####!%s导入数据失败\n" $i else printf "######%s导入数据成功!耗时:%.2f秒,累计耗时:%.2f秒\n" $i $cost $total_cost fi done |

执行命令:

nohup /home/appuser/tpcds-kit/exportdat.sh 2>/home/appuser/tpcds-kit/nohup.out &

2.6. 执行查询语句

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| #数据库名字 DB=testdb_100g total_cost=0 now=`date +%Y%m%d%H%M%S` for i in {1..99} do echo "begin run Q{i}, sql/queryi.sql , `date`" begin_time=`date +%s.%N` psql -h 172.0.0.1 -p 31000 -U zhouwh -d DB -f ./query{i}.sql > ./log/log_query{i}.out 2\>/tmp/null rc=? end_time=`date +%s.%N` cost=`echo "end_time-begin_time"|bc` total_cost=`echo "total_cost+cost"|bc` if [ $rc -ne 0 ] ; then printf "run Q%s fail, cost: %.2f, totalCost: %.2f, `date`\n" $i $cost total_cost else ROWS=\`grep 'rows' ./log/log_query{i}.out|tail -1` printf "###run Q%s succ, cost: %.2f, totalCost: %.2f, ROWS%s%s%s, `date`\n" $i $cost $total_cost $ROWS fi done |

2.7. 统计

cost时间快速统计

awk -F "," '{print $2}' 文件名 |awk -F ":" '{print $2}'