LoginSignup
0
1

More than 1 year has passed since last update.

【Redshift】約1TBのデータをS3にUNLOADしてみた

Last updated at Posted at 2022-04-11

背景・目的

AthenaでPartition Indexの検証を行うため、以前、こちらで用意したRedshiftのデータを再利用し環境を準備します。
また、UNLOADに要する時間を短縮するには、「1.何がポイントか?」、「2.どれだけ効果があるか」を検証します。

サマリ

  • 以前、こちらで試したUNLOADコマンドで、S3にデータをコピーしました。
  • 今回の検証で利用したデータのサイズは、949GB。
  • 検証では、スライス数とRowgroupsizeの組み合わせで6パターン試しました。
  • 結果は下表に記載しました。
    • Rowgroupsizeによる違いは、ほとんど見られませんでした。
パターン(スライス数-Rowgroupsize) クラスタ数(スライス数) Rowgroupsize 処理時間
8スライス-32MB 2(8) 32MB 2h 30m
8スライス-128MB 128MB 2h 30m
16スライス-32MB 4(16) 32MB 2h 4m
16スライス-128MB 128MB 2h 2m
32スライス-32MB 8(32) 32MB 1h 51m
32スライス-128MB 128MB 1h 51m
  • UNLOAD時間を短縮するポイントとして、ノード数(スライス数)を増やすこと。
  • スライス数を倍になることで、おおよそ10%〜20%程度、速度が向上するようでした。

実践

S3バケット作成

  • 事前にバケットを作成しておきます。

パーティションキーの選定

  • 以下のクエリを実行し、パーティションキー候補のカーディナリティを確認しておきます。
    • パーティション数は、2,526になります。
    • レコード数の最小は、62,168件、最大は7,494,332件でした。
select l_shipdate,count(1)  from lineitem  group by l_shipdate order by 2 limit 1

===
l_shipdate  count
1992-01-02	62168

~~~~

select l_shipdate,count(1)  from lineitem  group by l_shipdate order by 2 desc limit 1

===
l_shipdate  count
1997-07-03	7494332

image.png

UNLOAD

1.以下のコマンドで、UNLOADします。

UNLOAD ('select * from lineitem')
TO 's3://{バケット名}/lineitem'
IAM_ROLE 'arn:aws:iam::{アカウント}:role/{IAMロール}'
PARTITION BY (l_shipdate) INCLUDE
PARQUET 
MANIFEST 
ALLOWOVERWRITE
Rowgroupsize {32 mb 〜 128 mb}
MAXFILESIZE 256 mb
REGION 'ap-northeast-1'
  • 以下のオプションでUNLOADしています。
    • パーティションキーに、l_shipdateを指定。
      • INCLUDEで、ファイル内に含める。
    • Parquetファイル
    • 1ファイル256MBを上限とする。
    • Overwriteを許可。(デフォルトでは、S3にファイルがある場合、失敗する。)
    • Rowgroupsizeは、32MBと128MBとする。
      • 大きくすることで、行グループの数を減らしNW通信量が減らすことができる。

2.結果を確認します。想定通りカラム名=値でS3パスが出来ていました。

// manifestファイルが作成されています。
$ aws s3 ls {バケット名}/lineitem_8_128/ | grep -i manifest
2022-04-12 01:25:25    4515382 manifest
$ 


// S3パスは、l_shipdate=日付で出来ていました。
$ aws s3 ls {バケット名}/lineitem_8_128/ | head
                           PRE l_shipdate=1992-01-02/
                           PRE l_shipdate=1992-01-03/
                           PRE l_shipdate=1992-01-04/
                           PRE l_shipdate=1992-01-05/
                           PRE l_shipdate=1992-01-06/
                           PRE l_shipdate=1992-01-07/
                           PRE l_shipdate=1992-01-08/
                           PRE l_shipdate=1992-01-09/
                           PRE l_shipdate=1992-01-10/
                           PRE l_shipdate=1992-01-11/

// S3パスは、2526件(2527件- manifestファイル1件)で事前に調べた件数と一致しています。
$ aws s3 ls {バケット名}/lineitem_8_128/ | wc -l
    2527
$

3.ロードに要した時間は、サマリにまとめました。

考察

  • やはり、スライス数を増やし、並列度が増えることでUNLOADの速度は向上するようでした。
  • 一気にUNLOADしたい場合は、Redshiftのスライス数を一時的に増やし(拡張し)、そのあと縮退するような運用にすると良いかもしれません。
  • この結果が、何かの参考になれば幸いです。

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1