Skip to Content
スパーク定義ガイド
book

スパーク定義ガイド

by Bill Chambers, Matei Zaharia
March 2025
Intermediate to advanced
606 pages
9h
Japanese
O'Reilly Media, Inc.
Content preview from スパーク定義ガイド

第14章. 分散共有変数

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

レジリエンス分散データセット(RDD)インタフェースに加えて、Sparkの低レベルAPIの2つ目は、2種類の「分散共有変数」であるブロードキャスト変数とアキュムレータである。これらはユーザ定義関数(例えば、RDDやDataFrameのmap 関数)で使用できる変数で、クラスタ上で実行すると特殊化する。具体的には、アキュムレータはすべてのタスクからのデータを合計して共有結果にすることができ(例えば、ジョブの入力レコードのうちいくつが解析に失敗したかを確認できるカウンタを実装するため)、ブロードキャスト変数はすべてのワーカーノードに大きな値を保存し、クラスタに再送信することなく多くのSparkアクションで再利用することができる。この章では、各変数の動機と使い方について説明する。

ブロードキャスト変数

ブロードキャスト 変数は、その変数をファンクション・クロージャーでカプセル化することなく、クラスタ内で不変の値を効率的に共有できる方法である。タスク内でドライバノードの変数を使用する通常の方法は、関数クロージャ内でその変数を参照する(例えばmap 演算子)だけだが、これは特にルックアップテーブルやor 機械学習モデルのような大きな変数では非効率になることがある。その理由は、クロージャ内で変数を使うと、ワーカー・ノードで何度も(タスクごとに)デシリアライズしなければならないからだ。さらに、同じ変数を複数のSparkアクションやジョブで使用すると、1回ではなくジョブごとにワーカーに再送されることになる。

そこでブロードキャスト変数の出番だ。ブロードキャスト変数は、タスクごとにシリアライゼーションされるのではなく、クラスタ内のすべてのマシンにキャッシュされる共有の不変性変数である。典型的な使用例は、図14-1に示すように、エクゼキュータ上のメモリに収まる大きなルックアップテーブルを渡して、それを適応度関数で使用することである。

figure-1
図14-1. ブロードキャスト変数

例えば、単語や値のリストがあるとする:

// in Scala
val myCollection = "Spark The Definitive Guide : Big Data Processing Made Simple"
  .split(" ")
val words = spark.sparkContext.parallelize(myCollection, 2)
# in Python
my_collection = "Spark The Definitive Guide : Big Data Processing Made Simple"\
  .split(" ")
words = spark.sparkContext.parallelize(my_collection, 2)

単語リストを、何キロバイト、何メガバイト、あるいはギガバイトになる可能性のある他の情報で補完したい。SQLで考えれば、これは技術的には右結合である:

// in Scala
val supplementalData = Map("Spark" -> 1000 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

高性能Spark

高性能Spark

Holden Karau, Rachel Warren
生成AIの可視化

生成AIの可視化

Priyanka Vergadia, Valliappa Lakshmanan
ソフトウェア工学の基礎

ソフトウェア工学の基礎

Nathaniel Schutta, Dan Vega

Publisher Resources

ISBN: 9798341627567