SlideShare ist ein Scribd-Unternehmen logo
1 von 74
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
1
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
Solutions Architect 大薗 純平
2020/7/29
Amazon Redshift Advanced Guide
− 最新ベストプラクティスとアップデート
サービスカットシリーズ
[AWS Black Belt Online Seminar]
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2
自己紹介
大薗 純平 (おおぞの じゅんぺい)
@jostandard
アマゾン ウェブ サービス ジャパン
ソリューションアーキテクト
好きなサービス :
Amazon Redshift をはじめとした
Analytics サービス
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
3
AWS Black Belt Online Seminar とは
「サービス別」「ソリューション別」「業種別」のそれぞれのテーマに分かれて、アマゾ
ン ウェブ サービス ジャパン株式会社が主催するオンラインセミナーシリーズです。
質問を投げることができます!
• 書き込んだ質問は、主催者にしか見えません
• 今後のロードマップに関するご質問は
お答えできませんのでご了承下さい
① 吹き出しをクリック
② 質問を入力
③ Sendをクリック
Twitter ハッシュタグは以下をご利用ください
#awsblackbelt
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
4
内容についての注意点
• 本資料では2020年7月29日現在のサービス内容および価格についてご説明しています。最新の
情報はAWS公式ウェブサイト(http://aws.amazon.com)にてご確認ください。
• 資料作成には十分注意しておりますが、資料内の価格とAWS公式ウェブサイト記載の価格に相
違があった場合、AWS公式ウェブサイトの価格を優先とさせていただきます。
• 価格は税抜表記となっています。日本居住者のお客様には別途消費税をご請求させていただきま
す。
• AWS does not offer binding price quotes. AWS pricing is publicly available and is
subject to change in accordance with the AWS Customer Agreement available at
http://aws.amazon.com/agreement/. Any pricing information included in this
document is provided only as an estimate of usage charges for AWS services based on
certain information that you have provided. Monthly charges will be based on your
actual use of AWS services, and may vary from the estimates provided.
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
5
本日のアジェンダ
• Amazon Redshift 概要
• Amazon Redshift Spectrum を活用する
• ワークロード管理 (WLM) を活用する
• 最近のアップデート
• まとめ
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
6
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
Amazon Redshift 概要
© 2020, Amazon Web Services, Inc. or its Affiliates.
7
Amazon Redshift とは
DWH
BI
OLTP ERP CRM LOB デバイス ウェブ センサー ソーシャル
ビッグデータ処理
リアルタイム処理
機械学習
データレイク
Amazon Redshift
高速、スケーラブルで
費用対効果の高い
データウェアハウス
およびデータレイク
分析マネージドサービス
Amazon S3
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
8
Amazon Redshift によるレイクハウスアプローチ
データウェアハウスはデータレイクアーキテクチャの一部であり、
データを還流させることによって他のツールとの連携もよりスムーズに行える
© 2020, Amazon Web Services, Inc. or its Affiliates.
9
Amazon S3
データ分析
データ保存&
バックアップ
ETL コンテンツ配信
アーカイブ
データレイク (Amazon S3) を中心にサービスが連携
機械学習
ストリームデータ
BI Amazon Personalize Amazon Polly
Amazon Rekognition Amazon SageMaker
AWS Glue Amazon
Redshift
Amazon
Athena
Amazon QuickSight
Amazon EMR Amazon
EMR
Amazon
Kinesis
AWS IoT
Analytics
AWS IoT
Core
Amazon EBS
Amazon RDS AWS Backup
AWS
Storage Gateway
Amazon
CloudFront
AWS Elemental
MediaLive
Amazon Kinesis
Data Analytics
Amazon Glacier
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
10
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
Amazon Redshift Spectrum
を活用する
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
11
Amazon Redshift Spectrum
Redshift クエリを Amazon S3 に拡張し、データレイクアーキテクチャを強化
Amazon Redshift
S3 上のデータに
直接クエリが可能
多くのオープンファイル
フォーマットをサポート
Redshift 上のテーブル
と S3 上のデータを結合
してクエリを実行可能
Redshift
クエリエンジン
Redshift データ
Spectrum
データレイク
Amazon S3
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
12
Spectrumの基本的な使い方は、「AWSBlackBeltOnlineSeminar2017AmazonRedshiftUpdate最近追加された新機能とRedshiftSpectrum」をご参照
https://www.slideshare.net/AmazonWebServicesJapan/aws-black-belt-online-seminar-2017-amazon-redshift-update#13
Amazon Redshift Spectrum
アーキテクチャ
Amazon Redshift
JDBC/ODBC
...
1 2 3 4 N
Amazon S3
エクサバイトスケールの
オブジェクトストレージ
AWS Glue
データカタログ
Redshift Spectrum
大規模スケールアウト
コンピューティング
クエリ
SELECT COUNT(*)
FROM S3.EXT_TABLE
GROUP BY ...
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
13
Spectrum ユースケース : データレイクアーキテクチャ
• S3 上の多様なフォーマットのデータを用途に合わせたクエリエンジンで分析
• アクセス頻度の低いデータを S3 にオフロード
• 同じデータに対して他の AWS サービスによる分析を可能に
Amazon S3
AWS Glue
Amazon Redshift
Amazon QuickSight
クローラー データカタログ Amazon EMR
Amazon Athena
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
14
Spectrum ユースケース : データインジェストの簡素化
• Spectrum 外部テーブル経由の SQL を活用し、 Redshift にデータロードす
る前のデータ加工と変換ステップをシンプルに
Before
After
INSERT INTO TABLE AS or
(CREATE TABLE AS )
SELECT col1,sum(col2)..
FROM S3.xxx
WHERE …
GROUP BY …
COPY
ステージング
テーブル
未加工の
生ログ 整形 CSV
未加工の
生ログ
Amazon RedshiftAmazon Redshift
ターゲット
テーブル
Amazon Redshift
ターゲット
テーブル
INSERT
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
15
Spectrum ユースケース : ETL ツールとして活用
• Amazon Redshift を効率的でコスト効果の高い ETL ツールとして活用
• シンプルな SQL で CSV から Parquet へ変換
• Redshift は Pause & Resume 機能を活用
CSV
Amazon Redshift Spectrum
Amazon S3
Parquet
Amazon S3
Amazon Redshift Spectrum
Amazon EMR
Amazon Athena
Amazon SageMaker
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
16
Amazon Redshift Spectrum ベストプラクティス
1. ファイル/テーブル属性
2. パーティションプルーニング
3. Min/Max プルーニング
4. Spectrum 層へのプッシュダウン
5. データレイアウト
6. 実行計画の最適化
7. Redshift クラスターサイズ
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
17
1. ファイル/テーブル属性
• ファイルフォーマット
• 列指向フォーマットを選択(Parquet/ORC )
• ファイル内の列のブロックの単位で圧縮し、ファイル全体で圧縮しないよ
うにする
• 必要な列のみの選択の徹底
• コスト抑制とパフォーマンス向上
• 最適なファイルサイズ
• >= 128MB(列指向), >= 64MB(行指向)
• 適切なデータ型を選択
• string Vs varchar(<max length>)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
18
2. パーティションプルーニング
• 頻繁にフィルターされる列でパーティショニングする
• 不要なパーティションのスキャンをスキップできるため、
クエリパフォーマンスが向上
• コストの削減にも寄与する
• パーティションキーは時系列が一般的
• パーティションの粒度を細かくしすぎない
• コストは抑制できるがクエリパフォーマンスに
悪影響を及ぼす可能性がある
svl_s3partition_summary の total_partitions と qualified_partitions をチェック
year/month year/month/day/hour
20*12  240 Vs 20*12*30*24  172,800
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
19
3. Min/Max プルーニング
• Parquet, ORC など列指向フォーマット
の最小/最大値の統計を活用する
• 処理不要な Row Group / Stripe は
スキャンをスキップ可能
• コストを抑え、性能を向上
• つまり Redshift ローカルテーブルの
ゾーンマップ(*)と同じ考えが適用できる
• 頻繁に絞り込みを行うカラムでデータを
ソートしておくと効果的
https://parquet.apache.org/documentation/latest/
Parquet ファイルフォーマット
* 20200318 AWS Black Belt Online Seminar Amazon Redshift をご参照
https://www.slideshare.net/AmazonWebServicesJapan/20200318-aws-black-belt-
online-seminar-amazon-redshift#35
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
20
4. Spectrum 層へのプッシュダウン
• Spectrum にプッシュダウン可能な処理を意識する
• 多くの集計関数
• COUNT, SUM, AVG, MIN, MAX, GROUP BY など
• 文字列関数
• regex_replace, to_upper, date_trunc など
• 等価条件、LIKE、IS NULL、CASE WHEN など
• 単一カラムの DISTINCT は Spectrum にプッシュダウンされるが、
複数カラムの DISTINCT は GROUP BY に書き換える必要あり
クエリの処理がプッシュダウンされていることを確認するために
SVL_S3QUERY_SUMMARY の s3_scanned_rows / s3query_returned_rows をチェック
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
21
5. データレイアウト
• 小さなマスターテーブル/頻繁にクエリされるデータは Redshift 内部へ、
ファクトテーブル/アクセス頻度の低いデータは S3 へ
• ホットデータを Redshift 内部へ、ウォーム/コールドデータを S3 へ
• Redshift 内部テーブルと Spectrum 外部テーブル を Union する
Late binding view を活用し、ホットデータとウォーム/コールドデータを
1 つのクエリで分析
Late binding view
CREATE VIEW total_sales as
SELECT … FROM sales_last_month
UNION ALL
SELECT … FROM s3_external_schema.sales_historical
WITH NO SCHEMA BINDING;
© 2020, Amazon Web Services, Inc. or its Affiliates.
22
Bloom filters で Spectrum の結合クエリの性能が向上
外部テーブルと内部テーブルの結合を効率化して最大 2 倍高速に
Fact Table Scan in S3
Dimension Table Scan + Filters
Hash of Dimension Table
Bloom Filters
Hash Join
AGG
SORT + LIMIT
関連レコード
のみの転送
New
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
23
6. 実行計画の最適化
• テーブルプロパティの numRows を更新する
• 結合順などを最適化
ALTER TABLE spectrum_schema.event SET TABLE PROPERTIES
('numRows'='122857504');
• コストとパフォーマンスを常に意識してクエリを書く
• S3 からのスキャンを最小化
• 必要なカラムのみの選択
• 必要に応じてパーティショニングする
• Redshift ノードに転送するデータを極小化
• 効率的なアグリゲーションとフィルタ
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
24
7. Redshift クラスターサイズ
コンピュート
ノード #1
コンピュート
ノード #2
スライス#0
スライス#1
スライス#0
スライス#1
...
1
2
3
N
Spectrum Amazon S3Amazon Redshift...
スライス毎の
リクエストは最大10
Split 可能なファイル
および圧縮形式の場合、
内部的に分割して
読み込む可能性がある
+
トータルスライス数が増えると
Spectrum の並列度が上がる
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
25
7. Redshift クラスターサイズ
• パフォーマンスを最適化するために正しく Redshift クラスターを構成する
• Redshift の各スライスは Spectrum に対して並列にリクエストを投入
• クラスターのトータルスライス数の合計がパフォーマンスに影響
SELECT query, files, splits, avg_request_parallelism
FROM SVL_S3QUERY_SUMMARY WHERE query= xxxxx;
query | files | splits | avg_request_parallelism
------+-------+--------+-------------------------
xxxxx | 112 | 328 | 5
• avg_request_parallelism * クラスターのトータルスライスの値よりも
Splits 数の合計のほうが少ない場合、Redshift のノードを
増やしても Spectrum のパフォーマンスは向上しない可能性が高い
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
26
Redshift クラスターのトータルスライス数の確認
• STV_SLICES テーブルより確認可能
例
select node, count(slice) from stv_slices group by node order by node;
node | count
------+-------
0 | 16
1 | 16
2 | 16
3 | 16
4 | 16
5 | 16
6 | 16
7 | 16
(8 rows)
8 ノードで構成されており、
ノード毎に 16 スライスあることが確認できる
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
27
データレイクエクスポート
Amazon
Redshift
Parquet
Sales
(Table)
Amazon S3
UNLOAD
(‘select * from Sales where
sales_date = YYYYMMDD’)
TO ‘s3://mybucket/unload/Sales/’
FORMAT as PARQUET
PARTITION BY (sales_date);
Redshift テーブル上の過去データをParquet ファイルに変換
※テーブル定義は別途作成する(手動, Glue クローラー等)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
28
CTAS で簡単に Spectrum 外部テーブルを作成
Amazon
Redshift Sales
(Table)
Amazon S3
CREATE EXTERNAL TABLE
spectrum_schema.Sales_history
PARTITION BY (sales_date)
STORED as PARQUET
LOCATION
‘s3://mybucket/unload/Sales/’
AS select * from Sales
;
CTAS(Create Table As Select) で Redshift テーブルデータから
Spectrum 用の外部テーブルを容易に作成可能
Sales_history
(External Table)
Sales_history
(External Table)
Sales_history
(External Table)
パーティション指定
ファイル形式指定
S3 Path 指定
New
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
29
CTAS で簡単に Spectrum 外部テーブルを作成
CREATE EXTERNAL TABLE spectrum.supplier_new stored as parquet
location 's3://mybucket/unload/parquet/supplier_ctas/’
AS SELECT * FROM supplier WHERE s_suppkey BETWEEN 1 and 5000000;
INFO: 5000000 record(s) exported successfully.
CREATE EXTERNAL TABLE
SELECT * FROM svv_external_tables WHERE tablename = 'supplier_new';
-[ RECORD 1 ]-----+-----------------------------------------------------------------------------
schemaname | tpch_spectrum
tablename | supplier_new
location | s3://ojunpei-tpch/unload/parquet/supplier_ctas
input_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat
output_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat
serialization_lib | org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe
serde_parameters | {"serialization.format":"1"}
compressed | 0
parameters | {"EXTERNAL":"TRUE","numRows":"5000000","transient_lastDdlTime":"1595972202"}
tabletype |
New
Glue Data Catalog 上に
メタデータ(件数)も自動登録
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
30
Spectrum 外部テーブルへの書込(データ追加)も可能
Amazon
Redshift Sales
(Table)
Amazon S3
INSERT INTO
spectrum_schema.Sales_history
select * from Sales
where sales_date = YYYYMMDD
;
通常の INSERT INTO 構文で Spectrum 用の外部テーブルに
対して Redshift テーブルデータを追加可能
Sales_history
(External Table)
Sales_history
(External Table)
Sales_history
(External Table)
New
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
31
Spectrum 外部テーブルへの書込(データ追加)も可能
INSERT INTO spectrum.supplier_new
SELECT * FROM supplier WHERE s_suppkey BETWEEN 5000001 AND 10000000;
INFO: 5000000 record(s) exported successfully.
INSERT
SELECT * FROM svv_external_tables WHERE tablename = 'supplier_new';
-[ RECORD 1 ]-----+------------------------------------------------------------------------------
schemaname | tpch_spectrum
tablename | supplier_new
location | s3://ojunpei-tpch/unload/parquet/supplier_ctas
input_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat
output_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat
serialization_lib | org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe
serde_parameters | {"serialization.format":"1"}
compressed | 0
parameters | {"EXTERNAL":"TRUE","numRows":"10000000","transient_lastDdlTime":"1595972619"}
tabletype |
New
Glue Data Catalog 上の
メタデータ(件数)も自動更新
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
32
マテリアライズドビューが外部テーブルを参照可能に
Amazon
Redshift
Amazon S3
CREATE MATERIALIZED VIEW
sales_summary
AS select sales_date, sum(sales)
FROM
spectrum_schema.sales_history
GROUP BY sales_date;
Redshift Spectrum 外部テーブルのデータを
マテリアライズドビュー化
New
Sales_summary
(Materialized View)
Sales_history
(External Table)
Sales_history
(External Table)
Sales_history
(External Table)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
33
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
ワークロード管理 (WLM)
を活用する
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
34
DWH のワークロード管理
• DWH に対するクエリには様々なもの
があり、それぞれ処理される時間帯や
特性、期待される性能 (SLA) は異なる
• すべての処理を平等に扱うべきか?
• 処理に応じて適切なリソースを
割り当てたり、優先すべき処理が
他の処理によって妨げられないよう
ワークロードを管理できる仕組みは重要
DWH
ダッシュボード
定型レポート
アドホック分析
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
35
WLM (ワークロード管理) とは
• Redshift がクエリに対してどのようにリソース(メモリ/CPU/Disk IO)を
割り当てるかを決定づけるしくみ
• クエリが実行されると、必ず待ち行列 (キュー) にアサインされる
• キューはデフォルトで用意されているが、別途作成して増やすことも可能
で、クエリの種類(ユーザーグループ、クエリグループ)に応じてアサイン
先を振り分けることが可能
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
36
WLM の基本
• クエリには、キューで利用可能なリソース (スロット) が割り当てられる
• 通常 1 スロットが割り当てられるが、クエリ実行前にセッション内で
以下のコマンドを実行することで、複数スロットを割り当てることも可能
set WLM_QUERY_SLOT_COUNT to N; // N <= キューの総スロット数
キュー
クエリ1
スロット
クエリ1に割り当てられたスロット
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
37
WLM の基本
• キューで利用できるスロットがクエリで専有された場合、
後続のクエリは、実行中のクエリが完了もしくはタイムアウトして
スロットが空くまで実行待ち状態になる(FIFO キュー待ち)
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
38
WLM の基本
• クエリ処理がスロットに割り当てられたメモリに収まらない場合、
他のスロットは利用せず、一時ディスク領域を利用して処理を実行
• より低速な Disk IO ベースの処理になるため、性能が劣化してしまいがち
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
一時ディスク領域
Spill to disk
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
39
一時ディスク領域を使用したクエリの特定
• 分析クエリやバッチ実行中にディスク使用率が増加し、処理終了後には
元に戻るといったケースは、多くの場合クエリが複雑でメモリ溢れし、
処理が一時ディスクに落ちている可能性が高い
• システムビュー SVL_QUERY_SUMMARY(*) の is_diskbased 列に
‘t’ が含まれているクエリは WLM のメモリを使い切って
一時ディスク領域を使っているクエリ
• より詳細な情報を得るにはシステムテーブル STL_QUERY_METRICS(*)
の max_blocks_to_disk を確認
https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_SUMMARY.html
https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_METRICS.html
* 該当システムテーブル/ビューの詳細は以下をご参照
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
40
手動 WLM と自動 WLM
WLM には 手動 WLM と 自動 WLM があり、クラスター単位でどちらを使用す
るかを決定する(それぞれの機能は混在して使うことができない)
手動 WLM
• キューのメモリ配分や同時実行数を
静的に設定する
• 各ワークロードの使用メモリ領域を
明確に分離できる
• 処理が一時ディスクに落ちないよう、
適正な値を調整をしていく必要あり
• すべての処理で CPU, Disk IO リ
ソースは平等に扱われる
自動 WLM (デフォルト)
• クラスター全体で柔軟にリソースを
使用し、メモリ配分や同時実行数は
Redshift が自動で管理
• キューを優先度ごとに分け、与える
CPU, Disk IO リソースに差をつける
ことが可能
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
41
手動 WLM と自動 WLM
手動 WLM
8GB
Dashboar
d
1G
B
1G
B
1G
B
6GB 6GB 6GB
8GB
1G
B
1G
B
1G
B
ETL
Adhoc
メモリ:40%
同時実行:2
メモリ:15%
同時実行:6
メモリ:45%
同時実行:3
クラスターの総メモリ : 40GB クラスターの総メモリ : 40GB
自動 WLM (デフォルト)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
42
手動 WLM と自動 WLM - どちらを選択すべきなのか?
手動 WLM を選択したほうがいい場合
• 既に手動 WLM を使う形で検証済みで、問題が発生していない場合
• ある程度ワークロードが予測できており、各クエリに必要なメモリ容量、
同時実行数が定義できる場合
自動 WLM を選択したほうがいい場合
• 手動 WLM によってリソースを適切に使い切れていない場合
• ワークロードの予測がつかず、手動で設計していくのが困難な場合
• 自動 WLM を使う場合、クエリ優先度の機能を活用すべし
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
43
自動 WLM とクエリ優先度
ビジネスの優先度に応じてキューを
分け、処理の優先度を設定
優先度の高い処理には、自動的に
多くの CPU, IOリソースを割り当て
優先度はコマンドまたは QMR に
よって動的に変更が可能(後述)
簡単な設定で、
高い SLA が求められる処理を
優先的に処理することが可能
Amazon
Redshift
クラスター
リーダーノード
コンピュート
ノード
Workload
manager
…
Concurrency query slots = Auto
BI/分析
Priority: 通常
ETL
Priority: 高い
データサイエンス
Priority: 低い
キュー
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
44
自動 WLM とクエリ優先度
• ワークロード毎にキューを分け、相対的な優先度を設定することが可能
• 最高
• 高い
• 通常 (デフォルト)
• 低い
• 最低
• 優先度は以下のコマンドまたはクエリモニタリングルール (QMR) によって
動的に変更が可能
• CHANGE_QUERY_PRIORITY
• CHANGE_SESSION_PRIORITY
• CHANGE_USER_PRIORITY
※コマンドを利用すると、上記 5 つの優先度に加えて
スーパーユーザーのみが利用できる、 “最高”よりも
高優先度な "Critical” も設定可能
https://docs.aws.amazon.com/redshift/latest/dg/r_CHANGE_QUERY_PRIORITY.html
https://docs.aws.amazon.com/redshift/latest/dg/r_CHANGE_SESSION_PRIORITY.html
https://docs.aws.amazon.com/redshift/latest/dg/r_CHANGE_USER_PRIORITY.html
* 該当コマンドの詳細は以下をご参照
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
45
クエリモニタリングルール (QMR)
• キューには、クエリに関するルールを 25 まで作成し、そのルールの境界を
越えたクエリへのアクションを定義することが可能
• ルール : CPU 利用率、CPU 時間、ジョイン対象行数、Spectrumスキャンなど
• アクション : LOG(ログ), ABORT(中止), Change Priority(クエリの優先度を変更) *1,
HOP (ホップ) *2
例 : Spectrum 外部テーブルへのクエリ時、スキャン行が
1 億件、且つスキャン容量が10GB を越えたクエリは中止
する
*1 – 自動 WLM の場合のみ選択できるアクション
*2 – 手動 WLM の場合のみ選択できるアクション
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
46
自動 WLM とクエリ優先度の設定例
ETL 用キュー
• 遅延が許されず、常に一定の SLA が要求
される ETL 処理の優先度は「高い」に
• ただし、処理に 1 時間以上かかった場合は
優先度を「低い」に落とす (QMR で設定)
BI 用キュー
• BI ツールによる分析処理の優先度は「通常」に
その他
• 上記以外の処理の優先度は「最低」に
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
47
クエリ優先度の動き
キューで実行されているクエリよりも高い優先度のクエリがきた場合は?
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 低い 低い 低い
高い 高い
※手動 WLM の場合は FIFO になる
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
48
クエリ優先度の動き
キューで実行されているクエリよりも高い優先度のクエリがきた場合は?
=>優先度の高いクエリが優先して処理される
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 低い 低い 低い
高い 高い
優先度の低いクエリが
キューの外に退避(ホールド)
優先度の高いクエリが割り込み
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
49
クエリ優先度の動き
優先度の高いクエリが間断なくくる場合、優先度の低いクエリはどうなるか?
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 低い 低い 低い
高い 高い
・・・
クエリ100
高い
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
50
クエリ優先度の動き
優先度の高いクエリが間断なくくる場合、優先度の低いクエリはどうなるか?
=>優先度の低いクエリが永遠にキュー待ちになることがないよう動作する
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 低い 低い 低い
高い 高い
・・・
クエリ100
高い
内部のルーティングアルゴリズムに則り、
優先度の低いクエリも時間をかけて
徐々にスロットにアサインされていく
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
51
クエリ優先度の動き
優先度の低いクエリに、より速くスロットをアサインするためには?
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 低い 低い 低い
高い 高い
・・・
クエリ100
高い
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
52
クエリ優先度の動き
優先度の低いクエリに、より速くスロットをアサインするためには?
=>コマンドや QMR で優先度をより高いものに変更することで対応
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 最高 低い 低い
高い 高い
・・・
クエリ100
高い
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
53
クエリ優先度の動き
優先度の低いクエリに、より速くスロットをアサインするためには?
=>キューの「同時実行スケーリングモード」を自動に設定し、Concurrency
Scaling を利用
キュー
クエリ1 クエリ3 クエリ4クエリ2 クエリ5
クエリ6 クエリ7
高い 高い 低い 低い 低い
高い 高い
・・・
クエリ100
高い
Redshift Concurrency
Scaling cluster
https://www.slideshare.net/AmazonWebServicesJapan/202002
18-aws-black-belt-online-seminar-next-generation-redshift#31
* Concurrency Scaling の詳細は以下をご参照
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
54
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
最近のアップデート
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
55
Concurrency Scaling and Spectrum Usage Limit
Daily
Weekly
Monthly
を選択可能
Concurrency
Scaling の実行時
間の上限を指定
Alert
Log to system
table
Disable feature
を選択可能
日/週/月毎の単位で使用上限を設定し、コストをコントロールすることが可能に
Daily
Weekly
Monthly
を選択可能
Spectrum テー
ブルに対するス
キャン容量 (TB)
の上限を指定
Alert
Log to system
table
Disable feature
を選択可能
New
https://aws.amazon.com/jp/redshift/pricing/
Amazon Redshift の料金
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
56
Azure Active Directory SSO 連携と多要素認証 (MFA)
SAML 準拠のシングルサインオン(SSO)
• Redshift JDBC/ODBC ドライバー(*) は
業界標準の SAML ワークフローと
ブラウザベースの多要素認証 (MFA)
をサポート
• ADFS, Okta, PingFederate といった
オンプレミスの SSO プロバイダに加えて
Azure AD との連携も可能に
* JDBC ドライバーバージョン 1.2.37.1065 以降
ODBC ドライバーバージョン 1.4.11.1000 以降
JDBC/ODBC
Amazon
Redshift
Azure
AD
SAML
token
AWS Identity
and Access
Management
New
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
57
スキーマのストレージ制御 (Schema Quota)
スキーマが使用するディスク容量を制限することが可能
ALTER SCHEMA public QUOTA 100 TB;
CREATE SCHEMA sales_schema AUTHORIZATION sales QUOTA 500 GB;
CREATE SCHEMA dev_schema AUTHORIZATION developer QUOTA 10 TB;
sales_schema
スキーマ
public
スキーマ
dev_schema
スキーマ
schema | quota | disk_usage | disk_usage_pct
--------------+-----------+------------+----------------
public | 104857600 | 10022023 | 9.56
sales_schema | 512000 | 0 | 0
dev_schema | 10485760 | 0 | 0
作成上限 :
100TB
作成上限 :
500GB
作成上限 :
10TB
各スキーマの使用状況は以下のシステムテーブルより
モニタリング可能
• SVV_SCHEMA_QUOTA_STATE
• STL_SCHEMA_QUOTA_VIOLATIONS
Sales
ユーザー
developer
ユーザー
New
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
58
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
まとめ
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
59
まとめ
• Amazon Redshift には多くの機能があり、それらをうまく活用することに
より様々なユースケースに対応することが可能
• Amazon Redshift Spectrum はアップデートの多い機能のひとつ
積極的に活用することによって S3 データレイクとの連携を密にし、
更にコスト対効果が高くスケーラブルな分析環境を構築することが可能
• DWH に対するクエリには様々なものがあり、それぞれ処理される時間帯や
特性、期待される性能 (SLA) は異なる
ワークロード管理 (WLM) の機能を活用しながらワークロード全体の最適化
を図っていくことは重要
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
60
Q&A
お答えできなかったご質問については
AWS Japan Blog 「https://aws.amazon.com/jp/blogs/news/」にて
後日掲載します。
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
61
AWS の日本語資料の場所「AWS 資料」で検索
https://amzn.to/JPArchive
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
62
で[検索]AWS イベント
毎週”W-A個別技術相談会”を実施中
• AWSのソリューションアーキテクト(SA)に
対策などを相談することも可能
• 申込みはイベント告知サイトから
(https://aws.amazon.com/jp/about-aws/events/)
AWS Well-Architected 個別技術相談会
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
63
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
ご視聴ありがとうございました
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
64
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS 公式 Webinar
https://amzn.to/JPWebinar
過去資料
https://amzn.to/JPArchive
参考資料
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
65
WLM クエリ優先度を設定してみよう
前提
• 2 種類の異なるワークロードがあると仮定し、
各々の実行ユーザーが所属するユーザーグループ名は以下の通り
• ETL (バッチ) : etl_user
• BI 分析 : bi_user
• 上記のユーザーグループに所属したユーザーからクエリが投げられた際に
利用するキューを、クエリ優先度付きで作成する
• BI 分析よりも、ETL (バッチ) の処理を優先させたい
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
66
WLM クエリ優先度を設定してみよう
Redshift コンソール
設定 > ワークロード管理 から
パラメータグループを新規作成
※デフォルトパラメータグループは編集できない
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
67
WLM クエリ優先度を設定してみよう
①
WLM モードが「自動 WLM」であることの確認 (違っていれば変更)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
68
WLM クエリ優先度を設定してみよう
①
WLM モードが「自動 WLM」であることの確認 (違っていれば変更)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
69
WLM クエリ優先度を設定してみよう
ワークロードキューを編集する
②
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
70
WLM クエリ優先度を設定してみよう
キューを 2 つ追加する (「キューを追加」を 2 回押す)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
71
WLM クエリ優先度を設定してみよう
情報を入力して保存
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
72
WLM クエリ優先度を設定してみよう
クラスターメニューのプロパティタブよりデータベース設定を編集
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
73
WLM クエリ優先度を設定してみよう
作成したパラメータグループを選択してクラスターを変更
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
74
WLM クエリ優先度を設定してみよう
再起動を保留中の状態になったら、クラスターの再起動を実施
https://docs.aws.amazon.com/ja_jp/redshift/latest/mgmt/working-with-parameter-groups.html
クラスターに既に関連付けられているパラメータグループのパラメータ値を変
更したり、別のパラメータグループをクラスターに関連付けたりすることもで
きます。このような場合、更新したパラメータ値を有効にするためにクラス
ターの再起動が必要になることがあります。
Amazon Redshift パラメータグループ

Weitere ähnliche Inhalte

Mehr von Amazon Web Services Japan

202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用Amazon Web Services Japan
 
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdfAmazon Web Services Japan
 
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介Amazon Web Services Japan
 
Amazon QuickSight の組み込み方法をちょっぴりDD
Amazon QuickSight の組み込み方法をちょっぴりDDAmazon QuickSight の組み込み方法をちょっぴりDD
Amazon QuickSight の組み込み方法をちょっぴりDDAmazon Web Services Japan
 
マルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのことマルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのことAmazon Web Services Japan
 
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチAmazon Web Services Japan
 
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介Amazon Web Services Japan
 
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
202202 AWS Black Belt Online Seminar Amazon Connect Customer ProfilesAmazon Web Services Japan
 
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するためにAmazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するためにAmazon Web Services Japan
 
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨Amazon Web Services Japan
 
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介Amazon Web Services Japan
 
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介Amazon Web Services Japan
 
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...Amazon Web Services Japan
 
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピAmazon Web Services Japan
 
20211209 Ops-JAWS Re invent2021re-cap-cloud operations
20211209 Ops-JAWS Re invent2021re-cap-cloud operations20211209 Ops-JAWS Re invent2021re-cap-cloud operations
20211209 Ops-JAWS Re invent2021re-cap-cloud operationsAmazon Web Services Japan
 
20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報
20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報
20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報Amazon Web Services Japan
 
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをなAmazon Web Services Japan
 
202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN
202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN
202110 AWS Black Belt Online Seminar AWS Site-to-Site VPNAmazon Web Services Japan
 

Mehr von Amazon Web Services Japan (20)

202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
 
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
 
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
 
Amazon QuickSight の組み込み方法をちょっぴりDD
Amazon QuickSight の組み込み方法をちょっぴりDDAmazon QuickSight の組み込み方法をちょっぴりDD
Amazon QuickSight の組み込み方法をちょっぴりDD
 
マルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのことマルチテナント化で知っておきたいデータベースのこと
マルチテナント化で知っておきたいデータベースのこと
 
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
 
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
 
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
 
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するためにAmazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
 
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
 
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
 
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
 
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
 
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
 
20211209 Ops-JAWS Re invent2021re-cap-cloud operations
20211209 Ops-JAWS Re invent2021re-cap-cloud operations20211209 Ops-JAWS Re invent2021re-cap-cloud operations
20211209 Ops-JAWS Re invent2021re-cap-cloud operations
 
20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報
20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報
20211203 AWS Black Belt Online Seminar AWS re:Invent 2021アップデート速報
 
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
 
20211109 JAWS-UG SRE keynotes
20211109 JAWS-UG SRE keynotes20211109 JAWS-UG SRE keynotes
20211109 JAWS-UG SRE keynotes
 
20211109 bleaの使い方(基本編)
20211109 bleaの使い方(基本編)20211109 bleaの使い方(基本編)
20211109 bleaの使い方(基本編)
 
202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN
202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN
202110 AWS Black Belt Online Seminar AWS Site-to-Site VPN
 

Kürzlich hochgeladen

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 

Kürzlich hochgeladen (9)

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 

20200729 AWS Black Belt Online Seminar Amazon Redshift Advanced Guide −最新ベストプラクティスとアップデート

  • 1. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 1 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive Solutions Architect 大薗 純平 2020/7/29 Amazon Redshift Advanced Guide − 最新ベストプラクティスとアップデート サービスカットシリーズ [AWS Black Belt Online Seminar]
  • 2. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2 自己紹介 大薗 純平 (おおぞの じゅんぺい) @jostandard アマゾン ウェブ サービス ジャパン ソリューションアーキテクト 好きなサービス : Amazon Redshift をはじめとした Analytics サービス
  • 3. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 3 AWS Black Belt Online Seminar とは 「サービス別」「ソリューション別」「業種別」のそれぞれのテーマに分かれて、アマゾ ン ウェブ サービス ジャパン株式会社が主催するオンラインセミナーシリーズです。 質問を投げることができます! • 書き込んだ質問は、主催者にしか見えません • 今後のロードマップに関するご質問は お答えできませんのでご了承下さい ① 吹き出しをクリック ② 質問を入力 ③ Sendをクリック Twitter ハッシュタグは以下をご利用ください #awsblackbelt
  • 4. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 4 内容についての注意点 • 本資料では2020年7月29日現在のサービス内容および価格についてご説明しています。最新の 情報はAWS公式ウェブサイト(http://aws.amazon.com)にてご確認ください。 • 資料作成には十分注意しておりますが、資料内の価格とAWS公式ウェブサイト記載の価格に相 違があった場合、AWS公式ウェブサイトの価格を優先とさせていただきます。 • 価格は税抜表記となっています。日本居住者のお客様には別途消費税をご請求させていただきま す。 • AWS does not offer binding price quotes. AWS pricing is publicly available and is subject to change in accordance with the AWS Customer Agreement available at http://aws.amazon.com/agreement/. Any pricing information included in this document is provided only as an estimate of usage charges for AWS services based on certain information that you have provided. Monthly charges will be based on your actual use of AWS services, and may vary from the estimates provided.
  • 5. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 5 本日のアジェンダ • Amazon Redshift 概要 • Amazon Redshift Spectrum を活用する • ワークロード管理 (WLM) を活用する • 最近のアップデート • まとめ
  • 6. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 6 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive Amazon Redshift 概要
  • 7. © 2020, Amazon Web Services, Inc. or its Affiliates. 7 Amazon Redshift とは DWH BI OLTP ERP CRM LOB デバイス ウェブ センサー ソーシャル ビッグデータ処理 リアルタイム処理 機械学習 データレイク Amazon Redshift 高速、スケーラブルで 費用対効果の高い データウェアハウス およびデータレイク 分析マネージドサービス Amazon S3
  • 8. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 8 Amazon Redshift によるレイクハウスアプローチ データウェアハウスはデータレイクアーキテクチャの一部であり、 データを還流させることによって他のツールとの連携もよりスムーズに行える
  • 9. © 2020, Amazon Web Services, Inc. or its Affiliates. 9 Amazon S3 データ分析 データ保存& バックアップ ETL コンテンツ配信 アーカイブ データレイク (Amazon S3) を中心にサービスが連携 機械学習 ストリームデータ BI Amazon Personalize Amazon Polly Amazon Rekognition Amazon SageMaker AWS Glue Amazon Redshift Amazon Athena Amazon QuickSight Amazon EMR Amazon EMR Amazon Kinesis AWS IoT Analytics AWS IoT Core Amazon EBS Amazon RDS AWS Backup AWS Storage Gateway Amazon CloudFront AWS Elemental MediaLive Amazon Kinesis Data Analytics Amazon Glacier
  • 10. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 10 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive Amazon Redshift Spectrum を活用する
  • 11. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 11 Amazon Redshift Spectrum Redshift クエリを Amazon S3 に拡張し、データレイクアーキテクチャを強化 Amazon Redshift S3 上のデータに 直接クエリが可能 多くのオープンファイル フォーマットをサポート Redshift 上のテーブル と S3 上のデータを結合 してクエリを実行可能 Redshift クエリエンジン Redshift データ Spectrum データレイク Amazon S3
  • 12. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 12 Spectrumの基本的な使い方は、「AWSBlackBeltOnlineSeminar2017AmazonRedshiftUpdate最近追加された新機能とRedshiftSpectrum」をご参照 https://www.slideshare.net/AmazonWebServicesJapan/aws-black-belt-online-seminar-2017-amazon-redshift-update#13 Amazon Redshift Spectrum アーキテクチャ Amazon Redshift JDBC/ODBC ... 1 2 3 4 N Amazon S3 エクサバイトスケールの オブジェクトストレージ AWS Glue データカタログ Redshift Spectrum 大規模スケールアウト コンピューティング クエリ SELECT COUNT(*) FROM S3.EXT_TABLE GROUP BY ...
  • 13. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 13 Spectrum ユースケース : データレイクアーキテクチャ • S3 上の多様なフォーマットのデータを用途に合わせたクエリエンジンで分析 • アクセス頻度の低いデータを S3 にオフロード • 同じデータに対して他の AWS サービスによる分析を可能に Amazon S3 AWS Glue Amazon Redshift Amazon QuickSight クローラー データカタログ Amazon EMR Amazon Athena
  • 14. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 14 Spectrum ユースケース : データインジェストの簡素化 • Spectrum 外部テーブル経由の SQL を活用し、 Redshift にデータロードす る前のデータ加工と変換ステップをシンプルに Before After INSERT INTO TABLE AS or (CREATE TABLE AS ) SELECT col1,sum(col2).. FROM S3.xxx WHERE … GROUP BY … COPY ステージング テーブル 未加工の 生ログ 整形 CSV 未加工の 生ログ Amazon RedshiftAmazon Redshift ターゲット テーブル Amazon Redshift ターゲット テーブル INSERT
  • 15. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 15 Spectrum ユースケース : ETL ツールとして活用 • Amazon Redshift を効率的でコスト効果の高い ETL ツールとして活用 • シンプルな SQL で CSV から Parquet へ変換 • Redshift は Pause & Resume 機能を活用 CSV Amazon Redshift Spectrum Amazon S3 Parquet Amazon S3 Amazon Redshift Spectrum Amazon EMR Amazon Athena Amazon SageMaker
  • 16. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 16 Amazon Redshift Spectrum ベストプラクティス 1. ファイル/テーブル属性 2. パーティションプルーニング 3. Min/Max プルーニング 4. Spectrum 層へのプッシュダウン 5. データレイアウト 6. 実行計画の最適化 7. Redshift クラスターサイズ
  • 17. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 17 1. ファイル/テーブル属性 • ファイルフォーマット • 列指向フォーマットを選択(Parquet/ORC ) • ファイル内の列のブロックの単位で圧縮し、ファイル全体で圧縮しないよ うにする • 必要な列のみの選択の徹底 • コスト抑制とパフォーマンス向上 • 最適なファイルサイズ • >= 128MB(列指向), >= 64MB(行指向) • 適切なデータ型を選択 • string Vs varchar(<max length>)
  • 18. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 18 2. パーティションプルーニング • 頻繁にフィルターされる列でパーティショニングする • 不要なパーティションのスキャンをスキップできるため、 クエリパフォーマンスが向上 • コストの削減にも寄与する • パーティションキーは時系列が一般的 • パーティションの粒度を細かくしすぎない • コストは抑制できるがクエリパフォーマンスに 悪影響を及ぼす可能性がある svl_s3partition_summary の total_partitions と qualified_partitions をチェック year/month year/month/day/hour 20*12  240 Vs 20*12*30*24  172,800
  • 19. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 19 3. Min/Max プルーニング • Parquet, ORC など列指向フォーマット の最小/最大値の統計を活用する • 処理不要な Row Group / Stripe は スキャンをスキップ可能 • コストを抑え、性能を向上 • つまり Redshift ローカルテーブルの ゾーンマップ(*)と同じ考えが適用できる • 頻繁に絞り込みを行うカラムでデータを ソートしておくと効果的 https://parquet.apache.org/documentation/latest/ Parquet ファイルフォーマット * 20200318 AWS Black Belt Online Seminar Amazon Redshift をご参照 https://www.slideshare.net/AmazonWebServicesJapan/20200318-aws-black-belt- online-seminar-amazon-redshift#35
  • 20. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 20 4. Spectrum 層へのプッシュダウン • Spectrum にプッシュダウン可能な処理を意識する • 多くの集計関数 • COUNT, SUM, AVG, MIN, MAX, GROUP BY など • 文字列関数 • regex_replace, to_upper, date_trunc など • 等価条件、LIKE、IS NULL、CASE WHEN など • 単一カラムの DISTINCT は Spectrum にプッシュダウンされるが、 複数カラムの DISTINCT は GROUP BY に書き換える必要あり クエリの処理がプッシュダウンされていることを確認するために SVL_S3QUERY_SUMMARY の s3_scanned_rows / s3query_returned_rows をチェック
  • 21. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 21 5. データレイアウト • 小さなマスターテーブル/頻繁にクエリされるデータは Redshift 内部へ、 ファクトテーブル/アクセス頻度の低いデータは S3 へ • ホットデータを Redshift 内部へ、ウォーム/コールドデータを S3 へ • Redshift 内部テーブルと Spectrum 外部テーブル を Union する Late binding view を活用し、ホットデータとウォーム/コールドデータを 1 つのクエリで分析 Late binding view CREATE VIEW total_sales as SELECT … FROM sales_last_month UNION ALL SELECT … FROM s3_external_schema.sales_historical WITH NO SCHEMA BINDING;
  • 22. © 2020, Amazon Web Services, Inc. or its Affiliates. 22 Bloom filters で Spectrum の結合クエリの性能が向上 外部テーブルと内部テーブルの結合を効率化して最大 2 倍高速に Fact Table Scan in S3 Dimension Table Scan + Filters Hash of Dimension Table Bloom Filters Hash Join AGG SORT + LIMIT 関連レコード のみの転送 New
  • 23. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 23 6. 実行計画の最適化 • テーブルプロパティの numRows を更新する • 結合順などを最適化 ALTER TABLE spectrum_schema.event SET TABLE PROPERTIES ('numRows'='122857504'); • コストとパフォーマンスを常に意識してクエリを書く • S3 からのスキャンを最小化 • 必要なカラムのみの選択 • 必要に応じてパーティショニングする • Redshift ノードに転送するデータを極小化 • 効率的なアグリゲーションとフィルタ
  • 24. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 24 7. Redshift クラスターサイズ コンピュート ノード #1 コンピュート ノード #2 スライス#0 スライス#1 スライス#0 スライス#1 ... 1 2 3 N Spectrum Amazon S3Amazon Redshift... スライス毎の リクエストは最大10 Split 可能なファイル および圧縮形式の場合、 内部的に分割して 読み込む可能性がある + トータルスライス数が増えると Spectrum の並列度が上がる
  • 25. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 25 7. Redshift クラスターサイズ • パフォーマンスを最適化するために正しく Redshift クラスターを構成する • Redshift の各スライスは Spectrum に対して並列にリクエストを投入 • クラスターのトータルスライス数の合計がパフォーマンスに影響 SELECT query, files, splits, avg_request_parallelism FROM SVL_S3QUERY_SUMMARY WHERE query= xxxxx; query | files | splits | avg_request_parallelism ------+-------+--------+------------------------- xxxxx | 112 | 328 | 5 • avg_request_parallelism * クラスターのトータルスライスの値よりも Splits 数の合計のほうが少ない場合、Redshift のノードを 増やしても Spectrum のパフォーマンスは向上しない可能性が高い
  • 26. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 26 Redshift クラスターのトータルスライス数の確認 • STV_SLICES テーブルより確認可能 例 select node, count(slice) from stv_slices group by node order by node; node | count ------+------- 0 | 16 1 | 16 2 | 16 3 | 16 4 | 16 5 | 16 6 | 16 7 | 16 (8 rows) 8 ノードで構成されており、 ノード毎に 16 スライスあることが確認できる
  • 27. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 27 データレイクエクスポート Amazon Redshift Parquet Sales (Table) Amazon S3 UNLOAD (‘select * from Sales where sales_date = YYYYMMDD’) TO ‘s3://mybucket/unload/Sales/’ FORMAT as PARQUET PARTITION BY (sales_date); Redshift テーブル上の過去データをParquet ファイルに変換 ※テーブル定義は別途作成する(手動, Glue クローラー等)
  • 28. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 28 CTAS で簡単に Spectrum 外部テーブルを作成 Amazon Redshift Sales (Table) Amazon S3 CREATE EXTERNAL TABLE spectrum_schema.Sales_history PARTITION BY (sales_date) STORED as PARQUET LOCATION ‘s3://mybucket/unload/Sales/’ AS select * from Sales ; CTAS(Create Table As Select) で Redshift テーブルデータから Spectrum 用の外部テーブルを容易に作成可能 Sales_history (External Table) Sales_history (External Table) Sales_history (External Table) パーティション指定 ファイル形式指定 S3 Path 指定 New
  • 29. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 29 CTAS で簡単に Spectrum 外部テーブルを作成 CREATE EXTERNAL TABLE spectrum.supplier_new stored as parquet location 's3://mybucket/unload/parquet/supplier_ctas/’ AS SELECT * FROM supplier WHERE s_suppkey BETWEEN 1 and 5000000; INFO: 5000000 record(s) exported successfully. CREATE EXTERNAL TABLE SELECT * FROM svv_external_tables WHERE tablename = 'supplier_new'; -[ RECORD 1 ]-----+----------------------------------------------------------------------------- schemaname | tpch_spectrum tablename | supplier_new location | s3://ojunpei-tpch/unload/parquet/supplier_ctas input_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat output_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat serialization_lib | org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe serde_parameters | {"serialization.format":"1"} compressed | 0 parameters | {"EXTERNAL":"TRUE","numRows":"5000000","transient_lastDdlTime":"1595972202"} tabletype | New Glue Data Catalog 上に メタデータ(件数)も自動登録
  • 30. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 30 Spectrum 外部テーブルへの書込(データ追加)も可能 Amazon Redshift Sales (Table) Amazon S3 INSERT INTO spectrum_schema.Sales_history select * from Sales where sales_date = YYYYMMDD ; 通常の INSERT INTO 構文で Spectrum 用の外部テーブルに 対して Redshift テーブルデータを追加可能 Sales_history (External Table) Sales_history (External Table) Sales_history (External Table) New
  • 31. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 31 Spectrum 外部テーブルへの書込(データ追加)も可能 INSERT INTO spectrum.supplier_new SELECT * FROM supplier WHERE s_suppkey BETWEEN 5000001 AND 10000000; INFO: 5000000 record(s) exported successfully. INSERT SELECT * FROM svv_external_tables WHERE tablename = 'supplier_new'; -[ RECORD 1 ]-----+------------------------------------------------------------------------------ schemaname | tpch_spectrum tablename | supplier_new location | s3://ojunpei-tpch/unload/parquet/supplier_ctas input_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat output_format | org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat serialization_lib | org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe serde_parameters | {"serialization.format":"1"} compressed | 0 parameters | {"EXTERNAL":"TRUE","numRows":"10000000","transient_lastDdlTime":"1595972619"} tabletype | New Glue Data Catalog 上の メタデータ(件数)も自動更新
  • 32. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 32 マテリアライズドビューが外部テーブルを参照可能に Amazon Redshift Amazon S3 CREATE MATERIALIZED VIEW sales_summary AS select sales_date, sum(sales) FROM spectrum_schema.sales_history GROUP BY sales_date; Redshift Spectrum 外部テーブルのデータを マテリアライズドビュー化 New Sales_summary (Materialized View) Sales_history (External Table) Sales_history (External Table) Sales_history (External Table)
  • 33. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 33 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive ワークロード管理 (WLM) を活用する
  • 34. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 34 DWH のワークロード管理 • DWH に対するクエリには様々なもの があり、それぞれ処理される時間帯や 特性、期待される性能 (SLA) は異なる • すべての処理を平等に扱うべきか? • 処理に応じて適切なリソースを 割り当てたり、優先すべき処理が 他の処理によって妨げられないよう ワークロードを管理できる仕組みは重要 DWH ダッシュボード 定型レポート アドホック分析
  • 35. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 35 WLM (ワークロード管理) とは • Redshift がクエリに対してどのようにリソース(メモリ/CPU/Disk IO)を 割り当てるかを決定づけるしくみ • クエリが実行されると、必ず待ち行列 (キュー) にアサインされる • キューはデフォルトで用意されているが、別途作成して増やすことも可能 で、クエリの種類(ユーザーグループ、クエリグループ)に応じてアサイン 先を振り分けることが可能
  • 36. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 36 WLM の基本 • クエリには、キューで利用可能なリソース (スロット) が割り当てられる • 通常 1 スロットが割り当てられるが、クエリ実行前にセッション内で 以下のコマンドを実行することで、複数スロットを割り当てることも可能 set WLM_QUERY_SLOT_COUNT to N; // N <= キューの総スロット数 キュー クエリ1 スロット クエリ1に割り当てられたスロット
  • 37. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 37 WLM の基本 • キューで利用できるスロットがクエリで専有された場合、 後続のクエリは、実行中のクエリが完了もしくはタイムアウトして スロットが空くまで実行待ち状態になる(FIFO キュー待ち) キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7
  • 38. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 38 WLM の基本 • クエリ処理がスロットに割り当てられたメモリに収まらない場合、 他のスロットは利用せず、一時ディスク領域を利用して処理を実行 • より低速な Disk IO ベースの処理になるため、性能が劣化してしまいがち キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 一時ディスク領域 Spill to disk
  • 39. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 39 一時ディスク領域を使用したクエリの特定 • 分析クエリやバッチ実行中にディスク使用率が増加し、処理終了後には 元に戻るといったケースは、多くの場合クエリが複雑でメモリ溢れし、 処理が一時ディスクに落ちている可能性が高い • システムビュー SVL_QUERY_SUMMARY(*) の is_diskbased 列に ‘t’ が含まれているクエリは WLM のメモリを使い切って 一時ディスク領域を使っているクエリ • より詳細な情報を得るにはシステムテーブル STL_QUERY_METRICS(*) の max_blocks_to_disk を確認 https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_SUMMARY.html https://docs.aws.amazon.com/redshift/latest/dg/r_SVL_QUERY_METRICS.html * 該当システムテーブル/ビューの詳細は以下をご参照
  • 40. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 40 手動 WLM と自動 WLM WLM には 手動 WLM と 自動 WLM があり、クラスター単位でどちらを使用す るかを決定する(それぞれの機能は混在して使うことができない) 手動 WLM • キューのメモリ配分や同時実行数を 静的に設定する • 各ワークロードの使用メモリ領域を 明確に分離できる • 処理が一時ディスクに落ちないよう、 適正な値を調整をしていく必要あり • すべての処理で CPU, Disk IO リ ソースは平等に扱われる 自動 WLM (デフォルト) • クラスター全体で柔軟にリソースを 使用し、メモリ配分や同時実行数は Redshift が自動で管理 • キューを優先度ごとに分け、与える CPU, Disk IO リソースに差をつける ことが可能
  • 41. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 41 手動 WLM と自動 WLM 手動 WLM 8GB Dashboar d 1G B 1G B 1G B 6GB 6GB 6GB 8GB 1G B 1G B 1G B ETL Adhoc メモリ:40% 同時実行:2 メモリ:15% 同時実行:6 メモリ:45% 同時実行:3 クラスターの総メモリ : 40GB クラスターの総メモリ : 40GB 自動 WLM (デフォルト)
  • 42. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 42 手動 WLM と自動 WLM - どちらを選択すべきなのか? 手動 WLM を選択したほうがいい場合 • 既に手動 WLM を使う形で検証済みで、問題が発生していない場合 • ある程度ワークロードが予測できており、各クエリに必要なメモリ容量、 同時実行数が定義できる場合 自動 WLM を選択したほうがいい場合 • 手動 WLM によってリソースを適切に使い切れていない場合 • ワークロードの予測がつかず、手動で設計していくのが困難な場合 • 自動 WLM を使う場合、クエリ優先度の機能を活用すべし
  • 43. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 43 自動 WLM とクエリ優先度 ビジネスの優先度に応じてキューを 分け、処理の優先度を設定 優先度の高い処理には、自動的に 多くの CPU, IOリソースを割り当て 優先度はコマンドまたは QMR に よって動的に変更が可能(後述) 簡単な設定で、 高い SLA が求められる処理を 優先的に処理することが可能 Amazon Redshift クラスター リーダーノード コンピュート ノード Workload manager … Concurrency query slots = Auto BI/分析 Priority: 通常 ETL Priority: 高い データサイエンス Priority: 低い キュー
  • 44. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 44 自動 WLM とクエリ優先度 • ワークロード毎にキューを分け、相対的な優先度を設定することが可能 • 最高 • 高い • 通常 (デフォルト) • 低い • 最低 • 優先度は以下のコマンドまたはクエリモニタリングルール (QMR) によって 動的に変更が可能 • CHANGE_QUERY_PRIORITY • CHANGE_SESSION_PRIORITY • CHANGE_USER_PRIORITY ※コマンドを利用すると、上記 5 つの優先度に加えて スーパーユーザーのみが利用できる、 “最高”よりも 高優先度な "Critical” も設定可能 https://docs.aws.amazon.com/redshift/latest/dg/r_CHANGE_QUERY_PRIORITY.html https://docs.aws.amazon.com/redshift/latest/dg/r_CHANGE_SESSION_PRIORITY.html https://docs.aws.amazon.com/redshift/latest/dg/r_CHANGE_USER_PRIORITY.html * 該当コマンドの詳細は以下をご参照
  • 45. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 45 クエリモニタリングルール (QMR) • キューには、クエリに関するルールを 25 まで作成し、そのルールの境界を 越えたクエリへのアクションを定義することが可能 • ルール : CPU 利用率、CPU 時間、ジョイン対象行数、Spectrumスキャンなど • アクション : LOG(ログ), ABORT(中止), Change Priority(クエリの優先度を変更) *1, HOP (ホップ) *2 例 : Spectrum 外部テーブルへのクエリ時、スキャン行が 1 億件、且つスキャン容量が10GB を越えたクエリは中止 する *1 – 自動 WLM の場合のみ選択できるアクション *2 – 手動 WLM の場合のみ選択できるアクション
  • 46. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 46 自動 WLM とクエリ優先度の設定例 ETL 用キュー • 遅延が許されず、常に一定の SLA が要求 される ETL 処理の優先度は「高い」に • ただし、処理に 1 時間以上かかった場合は 優先度を「低い」に落とす (QMR で設定) BI 用キュー • BI ツールによる分析処理の優先度は「通常」に その他 • 上記以外の処理の優先度は「最低」に
  • 47. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 47 クエリ優先度の動き キューで実行されているクエリよりも高い優先度のクエリがきた場合は? キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 低い 低い 低い 高い 高い ※手動 WLM の場合は FIFO になる
  • 48. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 48 クエリ優先度の動き キューで実行されているクエリよりも高い優先度のクエリがきた場合は? =>優先度の高いクエリが優先して処理される キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 低い 低い 低い 高い 高い 優先度の低いクエリが キューの外に退避(ホールド) 優先度の高いクエリが割り込み
  • 49. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 49 クエリ優先度の動き 優先度の高いクエリが間断なくくる場合、優先度の低いクエリはどうなるか? キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 低い 低い 低い 高い 高い ・・・ クエリ100 高い
  • 50. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 50 クエリ優先度の動き 優先度の高いクエリが間断なくくる場合、優先度の低いクエリはどうなるか? =>優先度の低いクエリが永遠にキュー待ちになることがないよう動作する キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 低い 低い 低い 高い 高い ・・・ クエリ100 高い 内部のルーティングアルゴリズムに則り、 優先度の低いクエリも時間をかけて 徐々にスロットにアサインされていく
  • 51. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 51 クエリ優先度の動き 優先度の低いクエリに、より速くスロットをアサインするためには? キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 低い 低い 低い 高い 高い ・・・ クエリ100 高い
  • 52. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 52 クエリ優先度の動き 優先度の低いクエリに、より速くスロットをアサインするためには? =>コマンドや QMR で優先度をより高いものに変更することで対応 キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 最高 低い 低い 高い 高い ・・・ クエリ100 高い
  • 53. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 53 クエリ優先度の動き 優先度の低いクエリに、より速くスロットをアサインするためには? =>キューの「同時実行スケーリングモード」を自動に設定し、Concurrency Scaling を利用 キュー クエリ1 クエリ3 クエリ4クエリ2 クエリ5 クエリ6 クエリ7 高い 高い 低い 低い 低い 高い 高い ・・・ クエリ100 高い Redshift Concurrency Scaling cluster https://www.slideshare.net/AmazonWebServicesJapan/202002 18-aws-black-belt-online-seminar-next-generation-redshift#31 * Concurrency Scaling の詳細は以下をご参照
  • 54. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 54 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive 最近のアップデート
  • 55. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 55 Concurrency Scaling and Spectrum Usage Limit Daily Weekly Monthly を選択可能 Concurrency Scaling の実行時 間の上限を指定 Alert Log to system table Disable feature を選択可能 日/週/月毎の単位で使用上限を設定し、コストをコントロールすることが可能に Daily Weekly Monthly を選択可能 Spectrum テー ブルに対するス キャン容量 (TB) の上限を指定 Alert Log to system table Disable feature を選択可能 New https://aws.amazon.com/jp/redshift/pricing/ Amazon Redshift の料金
  • 56. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 56 Azure Active Directory SSO 連携と多要素認証 (MFA) SAML 準拠のシングルサインオン(SSO) • Redshift JDBC/ODBC ドライバー(*) は 業界標準の SAML ワークフローと ブラウザベースの多要素認証 (MFA) をサポート • ADFS, Okta, PingFederate といった オンプレミスの SSO プロバイダに加えて Azure AD との連携も可能に * JDBC ドライバーバージョン 1.2.37.1065 以降 ODBC ドライバーバージョン 1.4.11.1000 以降 JDBC/ODBC Amazon Redshift Azure AD SAML token AWS Identity and Access Management New
  • 57. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 57 スキーマのストレージ制御 (Schema Quota) スキーマが使用するディスク容量を制限することが可能 ALTER SCHEMA public QUOTA 100 TB; CREATE SCHEMA sales_schema AUTHORIZATION sales QUOTA 500 GB; CREATE SCHEMA dev_schema AUTHORIZATION developer QUOTA 10 TB; sales_schema スキーマ public スキーマ dev_schema スキーマ schema | quota | disk_usage | disk_usage_pct --------------+-----------+------------+---------------- public | 104857600 | 10022023 | 9.56 sales_schema | 512000 | 0 | 0 dev_schema | 10485760 | 0 | 0 作成上限 : 100TB 作成上限 : 500GB 作成上限 : 10TB 各スキーマの使用状況は以下のシステムテーブルより モニタリング可能 • SVV_SCHEMA_QUOTA_STATE • STL_SCHEMA_QUOTA_VIOLATIONS Sales ユーザー developer ユーザー New
  • 58. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 58 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive まとめ
  • 59. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 59 まとめ • Amazon Redshift には多くの機能があり、それらをうまく活用することに より様々なユースケースに対応することが可能 • Amazon Redshift Spectrum はアップデートの多い機能のひとつ 積極的に活用することによって S3 データレイクとの連携を密にし、 更にコスト対効果が高くスケーラブルな分析環境を構築することが可能 • DWH に対するクエリには様々なものがあり、それぞれ処理される時間帯や 特性、期待される性能 (SLA) は異なる ワークロード管理 (WLM) の機能を活用しながらワークロード全体の最適化 を図っていくことは重要
  • 60. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 60 Q&A お答えできなかったご質問については AWS Japan Blog 「https://aws.amazon.com/jp/blogs/news/」にて 後日掲載します。
  • 61. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 61 AWS の日本語資料の場所「AWS 資料」で検索 https://amzn.to/JPArchive
  • 62. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 62 で[検索]AWS イベント 毎週”W-A個別技術相談会”を実施中 • AWSのソリューションアーキテクト(SA)に 対策などを相談することも可能 • 申込みはイベント告知サイトから (https://aws.amazon.com/jp/about-aws/events/) AWS Well-Architected 個別技術相談会
  • 63. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 63 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive ご視聴ありがとうございました
  • 64. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 64 © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS 公式 Webinar https://amzn.to/JPWebinar 過去資料 https://amzn.to/JPArchive 参考資料
  • 65. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 65 WLM クエリ優先度を設定してみよう 前提 • 2 種類の異なるワークロードがあると仮定し、 各々の実行ユーザーが所属するユーザーグループ名は以下の通り • ETL (バッチ) : etl_user • BI 分析 : bi_user • 上記のユーザーグループに所属したユーザーからクエリが投げられた際に 利用するキューを、クエリ優先度付きで作成する • BI 分析よりも、ETL (バッチ) の処理を優先させたい
  • 66. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 66 WLM クエリ優先度を設定してみよう Redshift コンソール 設定 > ワークロード管理 から パラメータグループを新規作成 ※デフォルトパラメータグループは編集できない
  • 67. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 67 WLM クエリ優先度を設定してみよう ① WLM モードが「自動 WLM」であることの確認 (違っていれば変更)
  • 68. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 68 WLM クエリ優先度を設定してみよう ① WLM モードが「自動 WLM」であることの確認 (違っていれば変更)
  • 69. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 69 WLM クエリ優先度を設定してみよう ワークロードキューを編集する ②
  • 70. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 70 WLM クエリ優先度を設定してみよう キューを 2 つ追加する (「キューを追加」を 2 回押す)
  • 71. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 71 WLM クエリ優先度を設定してみよう 情報を入力して保存
  • 72. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 72 WLM クエリ優先度を設定してみよう クラスターメニューのプロパティタブよりデータベース設定を編集
  • 73. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 73 WLM クエリ優先度を設定してみよう 作成したパラメータグループを選択してクラスターを変更
  • 74. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 74 WLM クエリ優先度を設定してみよう 再起動を保留中の状態になったら、クラスターの再起動を実施 https://docs.aws.amazon.com/ja_jp/redshift/latest/mgmt/working-with-parameter-groups.html クラスターに既に関連付けられているパラメータグループのパラメータ値を変 更したり、別のパラメータグループをクラスターに関連付けたりすることもで きます。このような場合、更新したパラメータ値を有効にするためにクラス ターの再起動が必要になることがあります。 Amazon Redshift パラメータグループ