[AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

67
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc. AWS マイスターシリーズ Amazon Elastic MapReduce 2013.09.25 アマゾンデータサービスジャパン株式会社 ソリューションアーキテクト 大谷 晋平

Transcript of [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

Page 1: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

AWS マイスターシリーズ

Amazon Elastic MapReduce

2013.09.25

アマゾンデータサービスジャパン株式会社

ソリューションアーキテクト 大谷 晋平

Page 2: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

2

アジェンダ

ビッグデータとクラウド

Amazon Elastic MapReduce(EMR)

EMRとHadoopエコシステム

EMRアーキテクチャ

EMRアドバンスドトピック

まとめ

Page 3: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

ビッグデータとクラウドは最高の組み合わせ

ビッグデータ AWSクラウド: 膨大なデータセット 膨大、無制限のキャパシティ

実験的に繰り返し行われるデータの加工と分析

実験的に繰り返しインフラの構築や使用が可能

波の激しいワークロード 変化するワークロードに効率的に対応

結果は迅速に

1つのデータソースを並列されたコンピュートクラスタで処理

設定や管理が困難 マネージドサービス

Page 4: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

4

ビッグデータに必要なもの、全てAWSで。

Import Export

Glacier

S3

EC2

Redshift DynamoDB

EMR S3 Direct Connect

Page 5: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

5

ビッグデータに必要なもの、全てAWSで。

Import Export

Glacier

S3

EC2

Redshift DynamoDB

EMR S3 Direct Connect

Page 6: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

6

Page 7: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

7

Apache Hadoopとは?

Big Dataを扱うために:

– スケーラブルな分散ストレージ

– 低価格で柔軟に行うことが出来る分析

Hadoop は上記を満たすオープンソース製品

– HDFS(Hadoop Distributed File System) – 巨大なデータを扱えるバッチ処理用分散ファイルシステム。

– コモディティサーバに特化。

– MapReduce – 分散処理である煩わしい点をカバーしてくれる

Page 8: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

8

Apache Hadoopとは(2)

エンドユーザが受けるメリット

–誰でも入手可能

–スケーラブル

–柔軟性

– 実績も多く、PBオーダまでリニアにスケール可能な、分析基盤が誰でも使える

–4000台までスケール

Page 9: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

9

Hadoopエコシステム

Page 10: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

10

RDBMSとHadoopの違い

RDBMS

• 事前定義したスキーマ

• 1台で稼働する事が前提

• SQLによるアクセス

• リニアにスケールしない

• リアルタイム処理

• 小規模データ

• 構造化データ

Hadoop

スキーマなし

分散・協調して動く前提

SQLでない複数言語サポート

リニアにスケールする

バッチ処理

大規模データ

半構造化データ

Page 11: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

11

Hadoopの課題

Hadoopのスケーラビリティを活かすには大量のサーバが必要

購入してしまうと拡張するのも困難。 自由にノードを追加・縮小できない

データをHDFSだけに保存するのはリスク

• 信頼できるアーカイブ先にデータをシームレスにおいておきたい。

Page 12: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

Amazon Elastic MapReduce(EMR)

Page 13: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

13

Elastic MapReduceとは

3つのシステムの掛け算

Page 14: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

14

Elastic MapReduceとは

3つのシステムの掛け算

スケールする 分散バッチ処理 フレームワーク

スケールする コンピュート リソース

スケールする ストレージ リソース

Page 15: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

15

エコシステム

Elastic MapReduceとは

3つのシステムの掛け算+α

スケールする 分散バッチ処理 フレームワーク

スケールする コンピュート リソース

スケールする ストレージ リソース

Page 16: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

EMRの基本機能

Page 17: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

17

EMRの基本動作

1. データをS3にストア

Page 18: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

18

EMRの基本動作

1. データをS3にストア

2. 選択: Hadoopディストリビューション、ノード数、ノードタイプ、Hadoopのアプリ(Hive/Pig/HBase)

Page 19: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

19

EMRの基本動作

1. データをS3にストア

2. 選択: Hadoopディストリビューション、ノード数、ノードタイプ、Hadoopのアプリ(Hive/Pig/HBase)

3. クラスタの起動(EMRコンソール、SDKまたは

APIを使用)

Page 20: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

20

EMRの基本動作

1. データをS3にストア

2. 選択: Hadoopディストリビューション、ノード数、ノードタイプ、Hadoopのアプリ(Hive/Pig/HBase)

4. アウトプットをS3から取得

3. クラスタの起動(EMRコンソール、SDKまたは

APIを使用)

Page 21: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

21

EMRの基本機能

クラスタのリサイズも可能

Page 22: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

22

EMRの基本機能

同じデータセットに対し、処理内容でクラスタを並列

作成も可能

Page 23: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

23

EMRの基本機能

クラスタを終了すれば課金は停止

Page 24: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

24

EMRの基本機能

あるいは永続的に稼働してHDFS上にデータ保存も可能

Page 25: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

25

データの保管場所

HDFS (Hadoop Distributed File System) • ローカルディスク

• データローカリティの確保による優れたパフォーマンス

• High Storage(hs1)ノードは、ローカルで48TBを持つ

S3

• 99.9999999%の信頼性(11 9’s)

• バージョンコントロール可能

• 柔軟で無制限

• クラスタ間で同一のデータを共有が可能

Page 26: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

EMRとHadoopエコシステム

Page 27: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

EMR上でHiveやPigも簡単に

Pig: • 高レベルプログラ

ム言語 (Pig Latin) • UDFに対応 • データフロー/ETL

に最適

Hive: • Hadoop用のデータウエ

アハウス • SQLライクなクエリ言

語 (HiveQL) • 当初Facebookが開発

Page 28: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

HBase: • カラムナ型データベース • HDFS上で動作 • 疎データに最適 • ランダム リード・ライト • 巨大なテーブルに最適(数10

億行、数100万列)

Mahout: • 機械学習のためのライブ

ラリ • リコメンド、データマイ

ニング、クラスタリング、および頻度の高いItemsetマイニング

EMR上で HBaseやMahoutも簡単に

Page 29: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

Ganglia • 拡張性高い分散モニタリング

ツール • クラスタおよび個別ノードの

パフォーマンスを表示 • ブートストラップアクション

でインストール

R: • 統計解析コンピューティン

グとグラフィックスのための言語とソフトウエア環境

• 既にインストール済み

GangliaやRもEMRなら、すぐ利用可能

Page 30: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

更にSpark や Shark も動く

Shark: • Hiveで動くHive • 最大100倍高速 • Hive互換 • Yahoo、AirBnbなど

で使用

Spark: • インメモリーで

MapReduce • 最大100倍高速 • HDFS、HBase、S3対応 • UCバークレーにて開発

http://aws.amazon.com/articles/4926593393724923

Page 31: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

31

EMRはMapRディストリビューションにも対応

Amazon Hadoopディストリビューションに加えて、 MapRディストリビューションにも対応 • M3

• M5

• M7(新規追加) • http://aws.amazon.com/jp/elasticmapreduce/mapr

MapRの主な機能 • NFS/ODBC対応

• No NameNodeなHAアーキテクチャ

• HA Jobtrackerでジョブの喪失を回避

• Mirroringを使ってクラスタ間のデータを同期

• Zero HBase Administration

Page 32: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

32

S3DistCp

Apache DistCPの拡張モジュール

• AWS環境に最適化されたDistCp、特にS3

• S3とHDFS間で効率的なデータ転送を行うことが可能

• S3とS3の間でも同様

• 実体はMapReduce

• 転送と同時にサイズ変換・圧縮アルゴリズムの変更などが可能

• http://docs.amazonwebservices.com/ElasticMapReduce/latest/DeveloperGuide/UsingEMR_s3distcp.html

Page 33: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

33

S3DistCp

CloudFrontのログへの実行例 • S3上のmyawsbucket/cfから

• ローカルのHDFSへ

• GroupByで指定したデータだけ

• 128MBのLZOに圧縮しつつ転送

• 終わったらソースのファイルは削除

./elastic-mapreduce --jobflow j-3GY8JC4179IOK --jar \

/home/hadoop/lib/emr-s3distcp-1.0.jar \

--args '--src,s3://myawsbucket/cf,\

--dest,hdfs:///local,\

--groupBy,.*XABCD12345678.([0-9]+-[0-9]+-[0-9]+-[0-9]+).*,\

--targetSize,128,\

--outputCodec,lzo,--deleteOnSuccess'

Page 34: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

EMRアーキテクチャ

Page 35: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

EMR Hadoop Cluster

Amazon S3

Amazon SimpleDB

BI Apps

巨大なデータセットや、 膨大なログをアップロード データ

ソース

Code/ Script

s

Amazon S3

Service

Amazon Elastic MapReduce

HiveQL Pig Latin Cascading

MapReduce コード

複数のジョブフローのステップを実行

JDBC ODBC

HiveQL Pig Latin アドホック

クエリ

EMRの全体アーキテクチャ

Input Data

Output Data

メタデータ

Master

Instance

Group

Task

Instance

Group

Master

Node

Task Node

Task Node

Core

Instance

Group

HDFS

Core Node

Core Node

HDFS

Page 36: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

36

EMRのコンポーネント

インスタンスグループ

• Master, Core, Taskの3つ

Master Node

• ジョブ全体を管理。1台のみ起動。

Core Node

• HDFSのDataNodeとTaskTrackerを持つ。MapReduceも実行。増やせるが減らせない

Task Node • MapReduceのみを実行。HDFSを持たない

• 足し引き可能

Page 37: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

EMRアドバンスドトピック

Page 38: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

38

主にBest Practices for EMRから抜粋

トピック

EMRノードとサイズ

タスクノードをいつ使うか

S3上のファイルサイズ

最適化について

Page 39: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

39

主にBest Practices for EMRから抜粋

トピック

EMRノードとサイズ

タスクノードをいつ使うか

S3上のファイルサイズ

最適化について

Page 40: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

40

ベストプラクティスの適用できる場所は?

EMR/Hadoop全体としては、Input DataからReduceのoutputまでの 利用空間効率を高めることが重要

Input Data Map Slot Reduce Slot Shuffle &

Sort

Page 41: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

41

サイジングにおけるベストプラクティス

どうクラスタをサイジングする

べきか

Input Data Map Slot Reduce Slot Shuffle &

Sort

Page 42: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

42

EMRのノードとサイズ

• アプリケーションとして最も負荷がかかる部分はどこかの把握が大切 • HadoopのMap/Reduceスロット数、Heapサイズなどの設定はイ

ンスタンスごとにデフォルト値が決められている

• http://docs.aws.amazon.com/ja_jp/ElasticMapReduce/latest/DeveloperGuide/HadoopMemoryDefault_AMI2.2.html

• スタート地点としてはm1.xlarge

• メモリインテンシブなジョブにはm2/cc2

• CPUインテンシブなジョブにはcc2/c1x.large

• HDFSインテンシブな場合はHs1を使う

• M1.small/m1.largeはテスト用が現実的

Page 43: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

43

EMRのノードとサイズ

• いくつノードが必要かは(ほとんどの場合) データの入力サイズによる

• より大きいデータ入力サイズ=多くのMapper=多くのノード

• ジョブの完了までの期待値にもよる

• インスタンスサイズによって、一定量のMapper/Reducerサイズを持つ

• 多くのノード = 多くのMapper = Mapステージがより早く完了する

Page 44: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

44

主にBest Practices for EMRから抜粋

トピック

EMRノードとサイズ

タスクノードをいつ使うか

S3上のファイルサイズ

最適化について

Page 45: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

45

タスクノードをいつ使うか

• Mapperが大量に必要な時

• S3から大量データをロードするとき

• Select x,y,z from some_table = mapper jobだが、大

量の処理パワーが必要ないとき

• タスクノードの大量なMapperを一時的にスポットで

使って、HDFSへデータをロードしてシャットダウン

• 短時間でのジョブで大量に処理パワーが必要

な場合

Page 46: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

46

主にBest Practices for EMRから抜粋

トピック

EMRノードとサイズ

タスクノードをいつ使うか

S3上のファイルサイズ

最適化について

Page 47: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

47

S3上のファイルサイズ

• 小さいファイルは避ける

• 理由:Mapperのオーバヘッド

• JVMの初期化コスト: CPU/Mem

• 各Mapperは起動するのに約2秒

• 100MBのデータが10TB分なら、100,000 mapper x 2秒 = Mapperのセットアップだけで55時間

• これが1000MBのデータが10TB分なら、10,000 mapper x 2秒 = Mapperのセットアップは5時間

Page 48: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

48

S3上のファイルサイズ

• Hadoop用に最適なS3のファイルサイズは?

• 小さすぎると性能が出ない

• 勿論HDFSのブロックサイズよりは大きい方が良い(EMRのデフォルトは128MB)

• Hadoop用に最適なS3のファイルサイズは?

• スプリットできないもので1-2GBくらい

Page 49: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

49

S3上のファイルサイズ

• スプリットできるもの: LZO形式など

• 2-5GB程度がベスト

• 何故それくらいなのか?

• Mapper数が多すぎると、S3サイドでAPIスロットリングや単一キーアクセスが頻発する可能性

• S3は同一キーに対して大量のレンジGETしすぎると、スロットリング対象になる可能性が高い

Page 50: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

groupByで複数のファイルを結合しつつ、圧縮コーデックをgzipからlzoに変換してS3から(HDFS|S3)に転送。その際に1ファイルを1GB前後ずつに切り分ける。

50

$ elastic-mapreduce \

--create \

--jar s3://EMRBUCKET/libs/s3distcp/1.latest/s3distcp.jar \

--args \

'--src,s3://INPUTBUCKET/nginx/,\ --groupBy,.*([0-9]{8}-[0-9]{2}).*.gz, \

--outputCodec,lzo, \

--targetSize,1024, \

--dest,hdfs:///OUTPUTBUCKET/'

S3DistCpによるS3上のデータのサイズ変更

Page 51: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

hiveに最適なデータ配置にしておきたい場合は、hiveのinsert文を使ってデータをS3上の外部テーブルにINSERTしてやることでも実現可能。

51

hive> INSERT OVERWRITE INTO ${output_external_table}

SELECT * FROM ${input_external_table}

HiveのInsertによるデータの再配置

Page 52: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

52

S3 DistCpを使った再配置

web server

web server

web server

HDFSにロード

Flu

en

td S

3 P

lug

in

整理してS3に再配置

S3D

istC

p/H

ive

この時点だとファイルはまだ 小さいファイル

適切なファイルサイズに集約&

再分割

Page 53: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

53

圧縮

• 圧縮はなるべくしましょう • S3

• Mapperのアウトプット

• ディスク書き込みの削減

• シャッフルサイズの削減(NWに易しい)

• http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/IntermediateCompression_AMI2.3.html

• Reducerのアウトプット

• ディスク書き込みの削減

• Mapperのスピル

• ディスク書き込みの削減

splits 0 Map

Map

Map

Reduce

Reduce

Part 0

Part 1

Copy

SortMerge

Merge

Inputs

splits 1

splits 2

Compression

Page 54: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

54

圧縮

• 適切な圧縮形式を選びましょう • 速いが、圧縮効率が良くない

• 圧縮効率は良いが遅い

• スプリット可能か、そうではないか

Page 55: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

55

主にBest Practices for EMRから抜粋

トピック

EMRノードとサイズ

タスクノードをいつ使うか

S3上のファイルサイズ

最適化について

Page 56: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

56

アドバンスドな最適化

• 最も良い最適化はデータの構造化 (例えば賢いデータパーティショニング等)

• 効率的なデータ構造=Hadoopで処理するデータ量の抑制=高速なジョブ

Page 57: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

57

アドバンスドな最適化

• Hadoopはバッチフレームワーク

• データ処理の単位 = 時間から日にち単位

• 短時間すぎるジョブには向いていない

• 他のフレームワークのほうが向いている

• Twitter Storm

• Spark

• Redshift

Page 58: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

58

アドバンスドな最適化

• EMRはEMRチームが既にかなり最適化している • まずはデフォルト値を抑えよう

• http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/Default_Config_AMI2.3.html

• クラスタサイズが小さいと、EMRの設定の最適化はあまり効果がない

• AWSベストプラクティス:制約を恐れない

• インスタンスのコストは1時間単位なのでそれを念頭に置くこと

Page 59: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

59

アドバンスドな最適化

インスタンスを普通に追加するのがほとんどの場合で正解

Page 60: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

60

アドバンスドな最適化(続)

• Gangliaでモニタリング

• どこがボトルネックかをまずは発見する

• Memory

• CPU

• ディスクIO

• ネットワークIO

Page 61: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

61

CPU

• クラスタのCPU利用率は常に監視する

• CPUをフルに使い切っていない場合、ノード単体あたりのタスク数をあげる事を検討

• クラスタのノード数を減らす

Page 62: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

62

Memory

• Gangliaのメモリ項目を監視

• メモリを使い切っている場合は:

• Mapperタスクあたりのメモリ量を上げる

Page 63: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

63

ディスクIO

• ディスクIOを監視

• ディスクIOは大きなボトルネックになる可能性アリ。

• Mapperスピル

• Reducerスピル

• SPILLED_RECORDSメトリクスを監視して、メモリを増やすなりしてスピルする量を減らす(後述)

• 象本第2版 P195

Page 64: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

64

ディスクIO

• Mapperのスピルするデータ:

• MAPPER_SPILLED_RECORDS > MAPPER_OUTPUT_RECORDS = ディスクにスピルする量

• io.sort.mb パラメータを増やして、Mapperのメモリ量を増やす

• Combinerを使う

• Reducerでも同じ

Page 65: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

65

Network IO

• S3とEMRを併用するなら、 Gangliaでネットワークスループットは見ておくこと

• 各ノードのMapperのNICスループットを最大化する

• 例えば:

• 大きめのインスタンスで言えば800Mbps-2Gbpsは出る

• Gangliaでクラスタ全体のスループット < ノード数 x 800Mbps|2Gbps なら、Mapper数を増やす

Page 66: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

66

まとめ

EMRはビッグデータ処理のためのHadoopサービス

• EMR=EC2 x S3 x Hadoopエコシステム

Hadoopの運用管理自体は何も価値を生みません。よりデータ分析に時間を!

EMRではクラスタのサイズや大きさを柔軟に変更可能

ベストプラクティスも蓄積されつつあり、いよいよ本格普及期に入った

Page 67: [AWSマイスターシリーズ] Amazon Elastic MapReduce (EMR)

© 2012 Amazon.com, Inc. and its aff iliates. All rights reserved. May not be copied, modif ied or distributed in w hole or in part w ithout the express consent of Amazon.com, Inc.

67

追加のリソース

Amazon Elastic MapReduce(EMR)の概要 • http://aws.amazon.com/jp/elasticmapreduce/

EMRベストプラクティス • http://media.amazonwebservices.com/AWS_Amazon_EM

R_Best_Practices.pdf

Amazon EMR よくある質問 • http://aws.amazon.com/jp/elasticmapreduce/faqs/

Amazon EMR 料金表 • http://aws.amazon.com/jp/elasticmapreduce/pricing/