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 スパーク定義ガイド

第23章. プロダクションにおける構造化ストリーミング

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

このパートの前の章では、ユーザの視点から構造化ストリーミングを扱ってきた。当然ながら、これはあなたのアプリケーションの中核をなすものである。この章では、アプリケーションを開発した後、本番環境でStructured Streamingを堅牢に実行するために必要な演算子のいくつかを取り上げる。

Structured Streaming はApache Spark 2.2.0でproduction-readyとマークされた。これは、このリリースがproductionでの使用に必要な全ての機能を持ち、APIを安定させることを意味する。率直に言って、他の本番用Sparkアプリケーションの実行と大差ないため、多くの組織が既に本番システムで使用している。実際、Structured Streamingの設計者は、トランザクションソース/シンクやactly-once処理などの機能を通じて、可能な限り簡単に運用できるように努めた。この章では、Structured Streaming特有の主要な演算子について説明する。これは、第II部でSparkの演算子について見たり学んだりしたことをすべて補足するものである。

フォールトトレランスとチェックポイント機能

ストリーミング・アプリケーションにとって最も重要な演算子は障害回復である。クラスタ内のマシンが失われたり、適切なマイグレーションを行わずにスキーマが誤って変更されたり、あるいは意図的にクラスタやアプリケーションを再起動させたりと、障害は避けられない。このような場合でも、Structured Streamingを使えばアプリケーションを再起動するだけで復旧できる。これを行うには、チェックポイントと先読みログを使用するようにアプリケーションを設定する必要がある。具体的には、信頼できるファイルシステム(HDFS、S3、または互換性のあるファイルシステムなど)上のチェックポイントの場所に書き込むようにクエリを構成する必要がある。そして、Structured Streamingは、現在の中間状態の値だけでなく、全ての関連する進捗情報(例えば、与えられたトリガーで処理されたインスタンスのオフセットの範囲)を定期的にチェックポイントの場所に保存する。障害シナリオでは、アプリケーションを再起動し、同じチェックポイントの場所を指すようにするだけで、アプリケーションは自動的に状態を回復し、中断したところからデータ処理を開始する。アプリケーションに代わってこの状態を手動で管理する必要はない-Structured Streamingが代わりにやってくれるのだ。

チェックポイントを使用するには、アプリケーションを起動する前に、 writeStreamcheckpointLocation オプションでチェックポイントの場所を指定する。これは以下のように行う:

// in Scala
val static = spark.read.json("/data/activity-data")
val streaming = spark
  .readStream
  .schema(static.schema)
  .option("maxFilesPerTrigger", 10)
  .json("/data/activity-data")
  .groupBy("gt" ...
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