SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
Deep Dive Into
Takuya UESHIN
Data Engineering Meetup #1, Mar 2019
1
SQL
with Advanced Performance Tuning
2
About Me
- Software Engineer @databricks
- Apache Spark Committer
- Twitter: @ueshin
- GitHub: github.com/ueshin
DATABRICKS WORKSPACE
Databricks Delta ML Frameworks
DATABRICKS CLOUD SERVICE
DATABRICKS RUNTIME
Reliable & Scalable Simple & Integrated
Databricks Unified Analytics Platform
APIs
Jobs
Models
Notebooks
Dashboards End to end ML lifecycle
Spark SQL
A highly scalable and efficient relational
processing engine with ease-to-use APIs and
mid-query fault tolerance.
4
The not-so-secret truth...
5
is not only SQL.SQL
Spark SQL
6
Spark SQL
7
A compiler from queries to RDDs.
Performance Tuning for Optimal Plans
Run EXPLAIN Plan.
Interpret Plan.
Tune Plan.
8
Declarative APIs
9
Declarative APIs
何をしたいのか?
• SQL API: ANSI SQL:2003 / HiveQL.
• Dataset/DataFrame APIs: richer,
user-friendly な language-integrated
インターフェイス
10
Metadata Catalog
11
Metadata Catalog
• Persistent Hive metastore [Hive 0.12 - Hive 2.3.3]
• Session-local temporary view manager
• Cross-session global temporary view manager
• Session-local function registry
12
Performance Tips - Catalog
Partition metadata 取得のコスト:
- Hive metastore のアップグレード
- Cardinality の高いパーティションカラムを避ける
- Partition pruning predicates (improved in [SPARK-20331])
13
Cache Manager
14
Cache Manager
• プランが一致した場合にキャッシュデータと置き
換える
• Cross-session
• 初めて利用する時にキャッシュデータ作成
• 依存しているtable/viewのデータが更新される
とキャッシュデータを無効化
15
Performance Tips - Cache
Cache: 必ずしも速いわけではない
- ディスクに書き出される場合がある
- 必要なければキャッシュしないようにする
16
Optimizer
17
Optimizer
heuristics と cost ベースでプランの書き換え
18
• Outer join elimination
• Constraint propagation
• Join reordering
and many more.
• Column pruning
• Predicate push down
• Constant folding
Performance Tips - Optimizer
独自の Optimizer や Planner Rule の組み込み
• SparkSessionExtensions
• ExperimentalMethodsクラス
• var extraOptimizations: Seq[Rule[LogicalPlan]] = Nil
• var extraStrategies: Seq[Strategy] = Nil
• Examples in the Herman’s talk Deep Dive into Catalyst
Optimizer
• Join two intervals: http://dbricks.co/2etjIDY
19
Planner
20
Planner
• Logical PlanをPhysical Planへ (what to how)
• コストに基づいて最適な Physical Plan を選択
21
table1 table2
Join
broadcast
hash join
sort merge
join
OR
broadcast join has lower cost if
one table can fit in memory
table1 table2 table1 table2
Performance Tips - Join Selection
broadcast join vs shuffle join (broadcast の方が速い)
• spark.sql.autoBroadcastJoinThreshold
• 統計情報を最新に保つ
• broadcastJoin ヒント
22
Performance Tips - Equal Join
… t1 JOIN t2 ON t1.id = t2.id AND t1.value < t2.value
… t1 JOIN t2 ON t1.value < t2.value
Join 条件に少なくとも1つの equal 条件を入れる
23
Performance Tips - Equal Join
… t1 JOIN t2 ON t1.id = t2.id AND t1.value < t2.value
… t1 JOIN t2 ON t1.value < t2.value
24
O(n ^ 2)
O(n)
Query Execution
25
Query Execution
• Memory Manager: メモリ利用状況を追跡してtaskや
operator間のメモリを調整
• Code Generator: Physical PlanをコンパイルしてJava
コードを生成
• Tungsten Engine: CPUやメモリに対して効率的なバイ
ナリデータフォーマットやデータ構造
26
Performance Tips - Memory Manager
spark.executor.memory と spark.memory.fraction を、監視外メ
モリのために余裕を持って設定する. Sparkが監視できないメモ
リ領域がある(netty buffer, parquet writer buffer).
spark.memory.offHeap.enabled と spark.memory.offHeap.size
を設定して off-heapを有効化, それにあわせて
spark.executor.memory を減らす.
27
Whole Stage Code Generation
Performance Tip - WholeStage codegen
spark.sql.codegen.hugeMethodLimit の設定
バイトコードのサイズが8kバイトを超える大きな
メソッドはJITコンパイラがコンパイルできない
29
Data Sources
• computation と storage の分離
• Complete data pipeline:
• External storage がデータを供給
• Spark が処理
• Sparkのデータ処理がとても速い場合、データ
ソースがボトルネックになり得る
30
Scan Vectorization
• Vectorizationでより効率的なカラムなデータ読み込み
• JVMがSIMDを利用しやすい
• ……
Partitioning and Bucketing
• data skipping と pre-shuffle のためのファイルレイアウト
• 不要なIOとシャッフルを避けてスピードアップ
• The summit talk: http://dbricks.co/2oG6ZBL
Performance Tips - DataSource
• vectorized reading が可能なファイルフォーマット
を利用 (Parquet, ORC)
• ファイルベースのデータソースの場合には、
Patitioning や Bucketing を検討
33
Apache Spark™
• Use Cases
• Research
• Technical Deep Dives
AI
• Productionizing ML
• Deep Learning
• Cloud Hardware
Fields
• Data Science
• Data Engineering
• Enterprise
5000+ ATTENDEES
Practitioners:
Data Scientists, Data Engineers,
Analysts, Architects
Leaders:
Engineering Management, VPs,
Heads of Analytics & Data, CxOs
TRACKS
databricks.com/sparkaisummit
35
Nike: Enabling Data Scientists to bring their Models to Market
Facebook: Vectorized Query Execution in Apache Spark at Facebook
Tencent: Large-scale Malicious Domain Detection with Spark AI
IBM: In-memory storage Evolution in Apache Spark
Capital One: Apache Spark and Sights at Speed: Streaming, Feature
management and Execution
Apple: Making Nested Columns as First Citizen in Apache Spark SQL
EBay: Managing Apache Spark workload and automatic optimizing.
Google: Validating Spark ML Jobs
HP: Apache Spark for Cyber Security in big company
Microsoft: Apache Spark Serving: Unifying Batch, Streaming and
RESTful Serving
ABSA Group: A Mainframe Data Source for Spark SQL and Streaming
Facebook: an efficient Facebook-scale shuffle service
IBM: Make your PySpark Data Fly with Arrow!
Facebook : Distributed Scheduling Framework for Apache Spark
Zynga: Automating Predictive Modeling at Zynga with PySpark
World Bank: Using Crowdsourced Images to Create Image Recognition
Models and NLP to Augment Global Trade indicator
JD.com: Optimizing Performance and Computing Resource.
Microsoft: Azure Databricks with R: Deep Dive
ICL: Cooperative Task Execution for Apache Spark
Airbnb: Apache Spark at Airbnb
Netflix: Migrating to Apache Spark at Netflix
Microsoft: Infrastructure for Deep Learning in
Apache Spark
Intel: Game playing using AI on Apache Spark
Facebook: Scaling Apache Spark @ Facebook
Lyft: Scaling Apache Spark on K8S at Lyft
Uber: Using Spark Mllib Models in a Production
Training and Serving Platform
Apple: Bridging the gap between Datasets and
DataFrames
Salesforce: The Rule of 10,000 Spark Jobs
Target: Lessons in Linear Algebra at Scale with
Apache Spark
Workday: Lesson Learned Using Apache Spark
Thank you
Takuya UESHIN (ueshin@databricks.com)
36

Más contenido relacionado

La actualidad más candente

db tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとは
db tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとはdb tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとは
db tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとは
Koji Shinkubo
 

La actualidad más candente (20)

db tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとは
db tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとはdb tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとは
db tech showcase_2014_A14_Actian Vectorで得られる、BIにおける真のパフォーマンスとは
 
Struggle against crossdomain data complexity in Recruit Group
Struggle against crossdomain data complexity in Recruit GroupStruggle against crossdomain data complexity in Recruit Group
Struggle against crossdomain data complexity in Recruit Group
 
ゼロから始めるSparkSQL徹底活用!
ゼロから始めるSparkSQL徹底活用!ゼロから始めるSparkSQL徹底活用!
ゼロから始めるSparkSQL徹底活用!
 
Hive on Spark の設計指針を読んでみた
Hive on Spark の設計指針を読んでみたHive on Spark の設計指針を読んでみた
Hive on Spark の設計指針を読んでみた
 
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
Apache Arrow Flight – ビッグデータ用高速データ転送フレームワーク #dbts2021
 
Project Tungsten Bringing Spark Closer to Bare Meta (Hadoop / Spark Conferenc...
Project Tungsten Bringing Spark Closer to Bare Meta (Hadoop / Spark Conferenc...Project Tungsten Bringing Spark Closer to Bare Meta (Hadoop / Spark Conferenc...
Project Tungsten Bringing Spark Closer to Bare Meta (Hadoop / Spark Conferenc...
 
Quick Overview of Upcoming Spark 3.0 + α
Quick Overview of Upcoming Spark 3.0 + αQuick Overview of Upcoming Spark 3.0 + α
Quick Overview of Upcoming Spark 3.0 + α
 
20160127三木会 RDB経験者のためのspark
20160127三木会 RDB経験者のためのspark20160127三木会 RDB経験者のためのspark
20160127三木会 RDB経験者のためのspark
 
OLAP options on Hadoop
OLAP options on HadoopOLAP options on Hadoop
OLAP options on Hadoop
 
Yifeng spark-final-public
Yifeng spark-final-publicYifeng spark-final-public
Yifeng spark-final-public
 
Introduction new features in Spark 3.0
Introduction new features in Spark 3.0Introduction new features in Spark 3.0
Introduction new features in Spark 3.0
 
Apache Sparkやってみたところ
Apache SparkやってみたところApache Sparkやってみたところ
Apache Sparkやってみたところ
 
Introduction to Hadoop and Spark (before joining the other talk) and An Overv...
Introduction to Hadoop and Spark (before joining the other talk) and An Overv...Introduction to Hadoop and Spark (before joining the other talk) and An Overv...
Introduction to Hadoop and Spark (before joining the other talk) and An Overv...
 
Presto As A Service - Treasure DataでのPresto運用事例
Presto As A Service - Treasure DataでのPresto運用事例Presto As A Service - Treasure DataでのPresto運用事例
Presto As A Service - Treasure DataでのPresto運用事例
 
2016-02-08 Spark MLlib Now and Beyond@Spark Conference Japan 2016
2016-02-08 Spark MLlib Now and Beyond@Spark Conference Japan 20162016-02-08 Spark MLlib Now and Beyond@Spark Conference Japan 2016
2016-02-08 Spark MLlib Now and Beyond@Spark Conference Japan 2016
 
sparksql-hive-bench-by-nec-hwx-at-hcj16
sparksql-hive-bench-by-nec-hwx-at-hcj16sparksql-hive-bench-by-nec-hwx-at-hcj16
sparksql-hive-bench-by-nec-hwx-at-hcj16
 
Apache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory dataApache Arrow - A cross-language development platform for in-memory data
Apache Arrow - A cross-language development platform for in-memory data
 
Re:dash Use Cases at iPROS
Re:dash Use Cases at iPROSRe:dash Use Cases at iPROS
Re:dash Use Cases at iPROS
 
(LT)Spark and Cassandra
(LT)Spark and Cassandra(LT)Spark and Cassandra
(LT)Spark and Cassandra
 
Hive on Spark を活用した高速データ分析 - Hadoop / Spark Conference Japan 2016
Hive on Spark を活用した高速データ分析 - Hadoop / Spark Conference Japan 2016Hive on Spark を活用した高速データ分析 - Hadoop / Spark Conference Japan 2016
Hive on Spark を活用した高速データ分析 - Hadoop / Spark Conference Japan 2016
 

Similar a 2019.03.19 Deep Dive into Spark SQL with Advanced Performance Tuning

Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築
VOYAGE GROUP
 
M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...
M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...
M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...
日本マイクロソフト株式会社
 
Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築
Kenta Suzuki
 

Similar a 2019.03.19 Deep Dive into Spark SQL with Advanced Performance Tuning (20)

Developers.IO 2019 Effective Datalake
Developers.IO 2019 Effective DatalakeDevelopers.IO 2019 Effective Datalake
Developers.IO 2019 Effective Datalake
 
大量のデータ処理や分析に使えるOSS Apache Spark入門(Open Source Conference 2021 Online/Kyoto 発表資料)
大量のデータ処理や分析に使えるOSS Apache Spark入門(Open Source Conference 2021 Online/Kyoto 発表資料)大量のデータ処理や分析に使えるOSS Apache Spark入門(Open Source Conference 2021 Online/Kyoto 発表資料)
大量のデータ処理や分析に使えるOSS Apache Spark入門(Open Source Conference 2021 Online/Kyoto 発表資料)
 
Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築
 
Spark Summit 2014 の報告と最近の取り組みについて
Spark Summit 2014 の報告と最近の取り組みについてSpark Summit 2014 の報告と最近の取り組みについて
Spark Summit 2014 の報告と最近の取り組みについて
 
Synapse lakedatabase
Synapse lakedatabaseSynapse lakedatabase
Synapse lakedatabase
 
QConTokyo2015「Sparkを用いたビッグデータ解析 〜後編〜」
QConTokyo2015「Sparkを用いたビッグデータ解析 〜後編〜」QConTokyo2015「Sparkを用いたビッグデータ解析 〜後編〜」
QConTokyo2015「Sparkを用いたビッグデータ解析 〜後編〜」
 
大量のデータ処理や分析に使えるOSS Apache Spark入門 - Open Source Conference2020 Online/Fukuoka...
大量のデータ処理や分析に使えるOSS Apache Spark入門 - Open Source Conference2020 Online/Fukuoka...大量のデータ処理や分析に使えるOSS Apache Spark入門 - Open Source Conference2020 Online/Fukuoka...
大量のデータ処理や分析に使えるOSS Apache Spark入門 - Open Source Conference2020 Online/Fukuoka...
 
Deep Learning Lab - Microsoft Machine Learning meetup 2018/06/27 - 推論編
Deep Learning Lab - Microsoft Machine Learning meetup 2018/06/27 - 推論編Deep Learning Lab - Microsoft Machine Learning meetup 2018/06/27 - 推論編
Deep Learning Lab - Microsoft Machine Learning meetup 2018/06/27 - 推論編
 
大量のデータ処理や分析に使えるOSS Apache Sparkのご紹介(Open Source Conference 2020 Online/Kyoto ...
大量のデータ処理や分析に使えるOSS Apache Sparkのご紹介(Open Source Conference 2020 Online/Kyoto ...大量のデータ処理や分析に使えるOSS Apache Sparkのご紹介(Open Source Conference 2020 Online/Kyoto ...
大量のデータ処理や分析に使えるOSS Apache Sparkのご紹介(Open Source Conference 2020 Online/Kyoto ...
 
M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...
M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...
M06_DX を担うエンジニア向け Data & AI Analytics プラットフォームの最適解 ~ Azure Synapse 最新機能ご紹介 ~ ...
 
データ分析に必要なスキルをつけるためのツール~Jupyter notebook、r連携、機械学習からsparkまで~
データ分析に必要なスキルをつけるためのツール~Jupyter notebook、r連携、機械学習からsparkまで~データ分析に必要なスキルをつけるためのツール~Jupyter notebook、r連携、機械学習からsparkまで~
データ分析に必要なスキルをつけるためのツール~Jupyter notebook、r連携、機械学習からsparkまで~
 
【de:code 2020】 Power Platform で広がるデータ インテグレーションの世界 (1/2)
【de:code 2020】 Power Platform で広がるデータ インテグレーションの世界 (1/2)【de:code 2020】 Power Platform で広がるデータ インテグレーションの世界 (1/2)
【de:code 2020】 Power Platform で広がるデータ インテグレーションの世界 (1/2)
 
Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築Jenkinsとhadoopを利用した継続的データ解析環境の構築
Jenkinsとhadoopを利用した継続的データ解析環境の構築
 
JAWS DAYS 2019
JAWS DAYS 2019JAWS DAYS 2019
JAWS DAYS 2019
 
Azure Antenna AI 概要
Azure Antenna AI 概要Azure Antenna AI 概要
Azure Antenna AI 概要
 
Spark 2.0 What's Next (Hadoop / Spark Conference Japan 2016 キーノート講演資料)
Spark 2.0 What's Next (Hadoop / Spark Conference Japan 2016 キーノート講演資料)Spark 2.0 What's Next (Hadoop / Spark Conference Japan 2016 キーノート講演資料)
Spark 2.0 What's Next (Hadoop / Spark Conference Japan 2016 キーノート講演資料)
 
Microsoft AI セミナー - Microsoft AI Platform
Microsoft AI セミナー - Microsoft AI PlatformMicrosoft AI セミナー - Microsoft AI Platform
Microsoft AI セミナー - Microsoft AI Platform
 
Spark Analytics - スケーラブルな分散処理
Spark Analytics - スケーラブルな分散処理Spark Analytics - スケーラブルな分散処理
Spark Analytics - スケーラブルな分散処理
 
Hybrid Data Deliveryを活用してオンプレミスデータをQlik Cloudでリアルタイム活用!
Hybrid Data Deliveryを活用してオンプレミスデータをQlik Cloudでリアルタイム活用!Hybrid Data Deliveryを活用してオンプレミスデータをQlik Cloudでリアルタイム活用!
Hybrid Data Deliveryを活用してオンプレミスデータをQlik Cloudでリアルタイム活用!
 
2021/6/3 Deep Learning Lab - Azure Synapse Analytics Ignite & Build アップデートake
2021/6/3 Deep Learning Lab - Azure Synapse Analytics Ignite & Build アップデートake2021/6/3 Deep Learning Lab - Azure Synapse Analytics Ignite & Build アップデートake
2021/6/3 Deep Learning Lab - Azure Synapse Analytics Ignite & Build アップデートake
 

Más de Takuya UESHIN

Más de Takuya UESHIN (10)

Introducing Koalas 1.0 (and 1.1)
Introducing Koalas 1.0 (and 1.1)Introducing Koalas 1.0 (and 1.1)
Introducing Koalas 1.0 (and 1.1)
 
Koalas: Unifying Spark and pandas APIs
Koalas: Unifying Spark and pandas APIsKoalas: Unifying Spark and pandas APIs
Koalas: Unifying Spark and pandas APIs
 
Koalas: Unifying Spark and pandas APIs
Koalas: Unifying Spark and pandas APIsKoalas: Unifying Spark and pandas APIs
Koalas: Unifying Spark and pandas APIs
 
An Insider’s Guide to Maximizing Spark SQL Performance
 An Insider’s Guide to Maximizing Spark SQL Performance An Insider’s Guide to Maximizing Spark SQL Performance
An Insider’s Guide to Maximizing Spark SQL Performance
 
Apache Arrow and Pandas UDF on Apache Spark
Apache Arrow and Pandas UDF on Apache SparkApache Arrow and Pandas UDF on Apache Spark
Apache Arrow and Pandas UDF on Apache Spark
 
Failing gracefully
Failing gracefullyFailing gracefully
Failing gracefully
 
20140908 spark sql & catalyst
20140908 spark sql & catalyst20140908 spark sql & catalyst
20140908 spark sql & catalyst
 
Introduction to Spark SQL & Catalyst
Introduction to Spark SQL & CatalystIntroduction to Spark SQL & Catalyst
Introduction to Spark SQL & Catalyst
 
20110616 HBase勉強会(第二回)
20110616 HBase勉強会(第二回)20110616 HBase勉強会(第二回)
20110616 HBase勉強会(第二回)
 
20100724 HBaseプログラミング
20100724 HBaseプログラミング20100724 HBaseプログラミング
20100724 HBaseプログラミング
 

2019.03.19 Deep Dive into Spark SQL with Advanced Performance Tuning

  • 1. Deep Dive Into Takuya UESHIN Data Engineering Meetup #1, Mar 2019 1 SQL with Advanced Performance Tuning
  • 2. 2 About Me - Software Engineer @databricks - Apache Spark Committer - Twitter: @ueshin - GitHub: github.com/ueshin
  • 3. DATABRICKS WORKSPACE Databricks Delta ML Frameworks DATABRICKS CLOUD SERVICE DATABRICKS RUNTIME Reliable & Scalable Simple & Integrated Databricks Unified Analytics Platform APIs Jobs Models Notebooks Dashboards End to end ML lifecycle
  • 4. Spark SQL A highly scalable and efficient relational processing engine with ease-to-use APIs and mid-query fault tolerance. 4
  • 7. Spark SQL 7 A compiler from queries to RDDs.
  • 8. Performance Tuning for Optimal Plans Run EXPLAIN Plan. Interpret Plan. Tune Plan. 8
  • 10. Declarative APIs 何をしたいのか? • SQL API: ANSI SQL:2003 / HiveQL. • Dataset/DataFrame APIs: richer, user-friendly な language-integrated インターフェイス 10
  • 12. Metadata Catalog • Persistent Hive metastore [Hive 0.12 - Hive 2.3.3] • Session-local temporary view manager • Cross-session global temporary view manager • Session-local function registry 12
  • 13. Performance Tips - Catalog Partition metadata 取得のコスト: - Hive metastore のアップグレード - Cardinality の高いパーティションカラムを避ける - Partition pruning predicates (improved in [SPARK-20331]) 13
  • 15. Cache Manager • プランが一致した場合にキャッシュデータと置き 換える • Cross-session • 初めて利用する時にキャッシュデータ作成 • 依存しているtable/viewのデータが更新される とキャッシュデータを無効化 15
  • 16. Performance Tips - Cache Cache: 必ずしも速いわけではない - ディスクに書き出される場合がある - 必要なければキャッシュしないようにする 16
  • 18. Optimizer heuristics と cost ベースでプランの書き換え 18 • Outer join elimination • Constraint propagation • Join reordering and many more. • Column pruning • Predicate push down • Constant folding
  • 19. Performance Tips - Optimizer 独自の Optimizer や Planner Rule の組み込み • SparkSessionExtensions • ExperimentalMethodsクラス • var extraOptimizations: Seq[Rule[LogicalPlan]] = Nil • var extraStrategies: Seq[Strategy] = Nil • Examples in the Herman’s talk Deep Dive into Catalyst Optimizer • Join two intervals: http://dbricks.co/2etjIDY 19
  • 21. Planner • Logical PlanをPhysical Planへ (what to how) • コストに基づいて最適な Physical Plan を選択 21 table1 table2 Join broadcast hash join sort merge join OR broadcast join has lower cost if one table can fit in memory table1 table2 table1 table2
  • 22. Performance Tips - Join Selection broadcast join vs shuffle join (broadcast の方が速い) • spark.sql.autoBroadcastJoinThreshold • 統計情報を最新に保つ • broadcastJoin ヒント 22
  • 23. Performance Tips - Equal Join … t1 JOIN t2 ON t1.id = t2.id AND t1.value < t2.value … t1 JOIN t2 ON t1.value < t2.value Join 条件に少なくとも1つの equal 条件を入れる 23
  • 24. Performance Tips - Equal Join … t1 JOIN t2 ON t1.id = t2.id AND t1.value < t2.value … t1 JOIN t2 ON t1.value < t2.value 24 O(n ^ 2) O(n)
  • 26. Query Execution • Memory Manager: メモリ利用状況を追跡してtaskや operator間のメモリを調整 • Code Generator: Physical PlanをコンパイルしてJava コードを生成 • Tungsten Engine: CPUやメモリに対して効率的なバイ ナリデータフォーマットやデータ構造 26
  • 27. Performance Tips - Memory Manager spark.executor.memory と spark.memory.fraction を、監視外メ モリのために余裕を持って設定する. Sparkが監視できないメモ リ領域がある(netty buffer, parquet writer buffer). spark.memory.offHeap.enabled と spark.memory.offHeap.size を設定して off-heapを有効化, それにあわせて spark.executor.memory を減らす. 27
  • 28. Whole Stage Code Generation
  • 29. Performance Tip - WholeStage codegen spark.sql.codegen.hugeMethodLimit の設定 バイトコードのサイズが8kバイトを超える大きな メソッドはJITコンパイラがコンパイルできない 29
  • 30. Data Sources • computation と storage の分離 • Complete data pipeline: • External storage がデータを供給 • Spark が処理 • Sparkのデータ処理がとても速い場合、データ ソースがボトルネックになり得る 30
  • 32. Partitioning and Bucketing • data skipping と pre-shuffle のためのファイルレイアウト • 不要なIOとシャッフルを避けてスピードアップ • The summit talk: http://dbricks.co/2oG6ZBL
  • 33. Performance Tips - DataSource • vectorized reading が可能なファイルフォーマット を利用 (Parquet, ORC) • ファイルベースのデータソースの場合には、 Patitioning や Bucketing を検討 33
  • 34. Apache Spark™ • Use Cases • Research • Technical Deep Dives AI • Productionizing ML • Deep Learning • Cloud Hardware Fields • Data Science • Data Engineering • Enterprise 5000+ ATTENDEES Practitioners: Data Scientists, Data Engineers, Analysts, Architects Leaders: Engineering Management, VPs, Heads of Analytics & Data, CxOs TRACKS databricks.com/sparkaisummit
  • 35. 35 Nike: Enabling Data Scientists to bring their Models to Market Facebook: Vectorized Query Execution in Apache Spark at Facebook Tencent: Large-scale Malicious Domain Detection with Spark AI IBM: In-memory storage Evolution in Apache Spark Capital One: Apache Spark and Sights at Speed: Streaming, Feature management and Execution Apple: Making Nested Columns as First Citizen in Apache Spark SQL EBay: Managing Apache Spark workload and automatic optimizing. Google: Validating Spark ML Jobs HP: Apache Spark for Cyber Security in big company Microsoft: Apache Spark Serving: Unifying Batch, Streaming and RESTful Serving ABSA Group: A Mainframe Data Source for Spark SQL and Streaming Facebook: an efficient Facebook-scale shuffle service IBM: Make your PySpark Data Fly with Arrow! Facebook : Distributed Scheduling Framework for Apache Spark Zynga: Automating Predictive Modeling at Zynga with PySpark World Bank: Using Crowdsourced Images to Create Image Recognition Models and NLP to Augment Global Trade indicator JD.com: Optimizing Performance and Computing Resource. Microsoft: Azure Databricks with R: Deep Dive ICL: Cooperative Task Execution for Apache Spark Airbnb: Apache Spark at Airbnb Netflix: Migrating to Apache Spark at Netflix Microsoft: Infrastructure for Deep Learning in Apache Spark Intel: Game playing using AI on Apache Spark Facebook: Scaling Apache Spark @ Facebook Lyft: Scaling Apache Spark on K8S at Lyft Uber: Using Spark Mllib Models in a Production Training and Serving Platform Apple: Bridging the gap between Datasets and DataFrames Salesforce: The Rule of 10,000 Spark Jobs Target: Lessons in Linear Algebra at Scale with Apache Spark Workday: Lesson Learned Using Apache Spark
  • 36. Thank you Takuya UESHIN (ueshin@databricks.com) 36