工作中想把历史的APP日志结构化到Hive中进行查询,由于数据较大,需要进行压缩,根据Hive官方提供的几种压缩格式分别进行写入,读取,OLAP计算的性能测试,以求找到最好的压缩格式。
1.建立大表js_data
CREATE TABLE IF NOT EXISTS data_ysz.js_data (referer STRING,ip STRING,articleId STRING,catalogCode STRING,userAgent STRING,sessionId STRING,title STRING,deviceId STRING,url STRING,visitTime STRING,catalogId STRING,atype STRING,domain STRING,action STRING,visitDate STRING) ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe';
2.装载数据到js_data
load data inpath '' into table js_data
3.根据大表建立不同存储方式的分区表(依次为RCfile,ORC,sequencefile,parquet,Avro)
Create table js_data_partitioned_rcfile(referer STRING,ip STRING,articleId STRING,catalogCode STRING,userAgent STRING,sessionId STRING,title STRING,deviceId STRING,url STRING,visitTime STRING,catalogId STRING,atype STRING,domain STRING,action STRING) PARTITIONED BY (visitDate STRING) STORED AS RCfile
Create table js_data_partitioned_orc(referer STRING,ip STRING,articleId STRING,catalogCode STRING,userAgent STRING,sessionId STRING,title STRING,deviceId STRING,url STRING,visitTime STRING,catalogId STRING,atype STRING,domain STRING,action STRING)PARTITIONED BY (visitDate STRING) STORED AS ORC
Create table js_data_partitioned_sequencefile(referer STRING,ip STRING,articleId STRING,catalogCode STRING,userAgent STRING,sessionId STRING,title STRING,deviceId STRING,url STRING,visitTime STRING,catalogId STRING,atype STRING,domain STRING,action STRING) PARTITIONED BY (visitDate STRING) STORED AS SequenceFile
Create table js_data_partitioned_parquetfile(referer STRING,ip STRING,articleId STRING,catalogCode STRING,userAgent STRING,sessionId STRING,title STRING,deviceId STRING,url STRING,visitTime STRING,catalogId STRING,atype STRING,domain STRING,action STRING) PARTITIONED BY (visitDate STRING) STORED AS parquetfile
Create table js_data_partitioned_avrofile(referer STRING,ip STRING,articleId STRING,catalogCode STRING,userAgent STRING,sessionId STRING,title STRING,deviceId STRING,url STRING,visitTime STRING,catalogId STRING,atype STRING,domain STRING,action STRING) PARTITIONED BY (visitDate STRING) STORED AS Avro
4.基于如下SQL进行测试
select visitdate,count(*) as pv from 表名 where action = '1' and domain = 'static.scms.sztv.com.cn' group by visitdate order by pv;
存储格式 | ORC | Sequencefile | Parquet | RCfile | Avro |
数据压缩后大小 | 1.8G | 67.0G | 11G | 63.8G | 66.7G |
存储耗费时间 | 535.7s | 625.8s | 537.3s | 543.48 | 544.3 |
SQL查询响应速度 | 19.63s | 184.07s | 24.22s | 88.5s | 281.65s |
1.在压缩存储时间上,除Sequencefile外基本都相差无几。
2.数据压缩比例上ORC最优,相比textfile节省了50倍磁盘空间,parquet压缩性能也较好。
3.SQL查询速度而言,ORC与parquet性能较好,远超其余存储格式。
综合上述各种性能指标,建议工作中原始日志写入hive的存储格式都采用ORC或者parquet格式,这和目前主流的做法一致。