Hadoopチューニング >
おすすめの圧縮利用法 †
一度、ソースファイルを通常のテーブル(TextFile? 形式)にロードし、それをLZO圧縮(ブロックベース)を伴った SequenceFile? 形式のテーブルに投入してから利用しましょう。
比較的データ量が少ない場合(それでも数GBまで)には、ただ単に圧縮されたファイル(ただし、GzipかLZO)を通常のテーブル(TextFile? 形式)にロードするだけでも圧縮の効果が得られます。
圧縮データのロード †
以下は、内容は全く同じで圧縮形式の異なるデータをテーブル(TextFile? ストレージ)にロードし、同じクエリを実行した場合の結果です。
圧縮により消費領域が節約できるとともに、Gzip、LZO圧縮についてはクエリ応答時間が大幅に短縮されていることが分かります。LZO圧縮の利用がおすすめです。
ただし、TextFile? ストレージの圧縮はファイルベースなので、Mapタスク数が1になっている点に注意する必要があります。 大規模データでは(分散処理が見込めないので)急激に速度が低下する恐れがありますので、ストレージに SequenceFile? を利用することをおすすめします。
テストログ †
HDFS上のファイルのロードが高速なのは、HDFS上の mv (ただしHiveの)だからです。コピーされないことに注意が必要です。
Gzip †
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv.gz'
> overwrite INTO TABLE postcodes;
Loading data to table postcodes
OK
Time taken: 9.007 seconds
grunt> ls / user/ hive/ warehouse/ postcodes
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes/ postcodes.x100.csv.gz< r 1 > 207106404
hive> SELECT org_code, count( org_code) FROM postcodes GROUP BY org_code;
...
Time taken: 92.241 seconds
LZO †
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv.lzo'
> overwrite INTO TABLE postcodes;
Loading data to table postcodes
OK
Time taken: 0.538 seconds
grunt> ls / user/ hive/ warehouse/ postcodes
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes/ postcodes.x100.csv.lzo< r 1 > 331001547
Time taken: 88.795 seconds
Bzip2 †
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv.bz2'
> overwrite INTO TABLE postcodes;
Loading data to table postcodes
OK
Time taken: 0.544 seconds
grunt> ls / user/ hive/ warehouse/ postcodes
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes/ postcodes.x100.csv.bz2< r 1 > 144019527
hive> SELECT org_code, count( org_code) FROM postcodes GROUP BY org_code;
...
Time taken: 214.87 seconds
SequenceFile? の利用 †
以下は、各ストレージに全く同じデータを投入し、同じクエリを実行した場合の結果です。
圧縮により消費領域が節約できるとともに、Deflate、LZO圧縮についてはクエリ応答時間が大幅に短縮されていることが分かります。LZOもしくはDeflate圧縮を伴った SequenceFile? の利用がおすすめです。
No. ストレージタイプ データ量 ロード時間(秒) クエリ応答時間(秒) Map数 詳細 1 テキストファイル(raw) 1,592,052,200 - 165.719 24 textfile_no_compress001.png2 SequenceFile? (Deflate圧縮)229,036,051 1186.357 89.213 4 seqfile_deflate_compress001.png3 SequenceFile? (LZO圧縮)414,012,342 946.145 95.439 6 seqfile_lzo_compress001.png4 SequenceFile? (Bzip2圧縮)159,883,185 2,307.423 166.13 3 seqfile_bzip2_compress001.png
テストログ †
テキストファイル †
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv'
> overwrite INTO TABLE postcodes;
Loading data to table postcodes
OK
Time taken: 0.367 seconds
grunt> ls / user/ hive/ warehouse/ postcodes
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes/ postcodes.x100.csv< r 1 > 1592052200
hive> SELECT org_code, count( org_code) FROM postcodes GROUP BY org_code;
...
Time taken: 165.719 seconds
SequenceFile? (Deflate圧縮) †
hive> set hive.exec.compress.output=true ;
hive> set mapred.output.compression.type=BLOCK;
hive> INSERT OVERWRITE TABLE postcodes_seq SELECT * FROM postcodes;
...
Loading data to table postcodes_seq
12287400 Rows loaded to postcodes_seq
OK
Time taken: 1186.357 seconds
grunt> ls / user/ hive/ warehouse/ postcodes_seq
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes_seq/ attempt_201007141806_0002_r_000000_0< r 1 > 229036051
hive> SELECT org_code, count( org_code) FROM postcodes_seq GROUP BY org_code;
...
Time taken: 89.213 seconds
SequenceFile? (LZO圧縮) †
hive> set hive.exec.compress.output=true ;
hive> set mapred.output.compression.type=BLOCK;
hive> set mapred.output.compression.codec=com.hadoop.compression.lzo.LzoCodec;
hive> INSERT OVERWRITE TABLE postcodes_seq SELECT * FROM postcodes;
...
Loading data to table postcodes_seq
12287400 Rows loaded to postcodes_seq
OK
Time taken: 946.145 seconds
grunt> ls / user/ hive/ warehouse/ postcodes_seq
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes_seq/ attempt_201007141806_0011_r_000000_0< r 1 > 206579657
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes_seq/ attempt_201007141806_0011_r_000001_0< r 1 > 207432685
hive> SELECT org_code, count( org_code) FROM postcodes_seq GROUP BY org_code;
...
Time taken: 95.439 seconds
SequenceFile? (Bzip2圧縮) †
hive> set hive.exec.compress.output=true ;
hive> set mapred.output.compression.type=BLOCK;
hive> set mapred.output.compression.codec=org.apache.hadoop.io.compress.BZip2Codec;
hive> INSERT OVERWRITE TABLE postcodes_seq SELECT * FROM postcodes;
...
Loading data to table postcodes_seq
12287400 Rows loaded to postcodes_seq
OK
Time taken: 2307.423 seconds
grunt> ls / user/ hive/ warehouse/ postcodes_seq
hdfs:// localhost:9000 / user/ hive/ warehouse/ postcodes_seq/ attempt_201007141806_0014_r_000000_0< r 1 > 159883185
hive> SELECT org_code, count( org_code) FROM postcodes_seq GROUP BY org_code;
...
Time taken: 166.13 seconds
HDFS上のファイルのSequenceFile? テーブルへのロードは不可 †
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv'
> overwrite INTO TABLE postcodes_seq;
Loading data to table postcodes_seq
Failed with exception Wrong file format. Please check the file's format.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv.gz'
> overwrite INTO TABLE postcodes_seq;
Loading data to table postcodes_seq
Failed with exception Wrong file format. Please check the file's format.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv.lzo'
> overwrite INTO TABLE postcodes_seq;
Loading data to table postcodes_seq
Failed with exception Wrong file format. Please check the file's format.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
hive> LOAD DATA inpath '/user/hadoop/work/postcodes.x100.csv.bz2'
> overwrite INTO TABLE postcodes_seq;
Loading data to table postcodes_seq
Failed with exception Wrong file format. Please check the file's format.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
データの圧縮ストア †
TODO
テストの詳細 †
概要 †
サンプルデータは、例によって郵便番号データを100倍に増やしたもので、無圧縮で1.48GBのサイズになります。
テスト環境 †
No. 項目 内容 備考 1 CPU Intel Core Duo T2300 1.66GHz 2 メモリ 4GB ただし、32bit環境。 3 OS Ubuntu 9.04 4 JDK OpenJDK 6 5 Hadoop Ver. 0.20.2, r911707、1台で擬似分散モード 6 Hive Ver. 0.5.0
スキーマ †
テストに用いたテーブルの定義は以下の通りです。
CREATE TABLE postcodes (
org_code string,
old_postcode string,
postcode string,
todoufuken_yomi string,
shikuchoson_yomi string,
choiki_yomi string,
todoufuken string,
shikuchoson string,
choiki string,
flag1 int,
flag2 int,
flag3 int,
flag4 int,
flag5 int,
flag6 int
)
row format delimited
FIELDS terminated BY ','
LINES terminated BY '\n ' ;
CREATE TABLE postcodes_seq (
org_code string,
old_postcode string,
postcode string,
todoufuken_yomi string,
shikuchoson_yomi string,
choiki_yomi string,
todoufuken string,
shikuchoson string,
choiki string,
flag1 int,
flag2 int,
flag3 int,
flag4 int,
flag5 int,
flag6 int
)
row format delimited
FIELDS terminated BY ','
LINES terminated BY '\n '
STORED AS SEQUENCEFILE;
リソース †