Skip to Content
Apache Spark によるストリーム処理
book

Apache Spark によるストリーム処理

by Gerard Maas, Francois Garillot
May 2025
Intermediate to advanced
452 pages
6h 3m
Japanese
O'Reilly Media, Inc.
Content preview from Apache Spark によるストリーム処理

第24章 チェックポイント チェックポイント

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

チェックポインティングという行為は、ステートフル・ストリーミング・アプリケーションを再起動するために必要な情報を、情報を失うことなく、その時点までに見たすべてのデータを再処理することなく、定期的に保存することである。

チェックポインティングは、ステートフルなSpark Streamingアプリケーションを扱う際に特に注意すべきテーマである。 チェックポインティングがなければ、ステートフルなストリーミングアプリケーションを再起動する際に、アプリケーションを停止した時点までの状態を再構築する必要がある。 ウィンドウ演算子の場合、この再構築プロセスは何時間ものデータで構成される可能性があり、より巨大な中間ストレージが必要になる。 チェックポイントがなければ、Webサイトの各ページへの訪問者数をカウントするような単純なステートフル・アプリケーションでさえ、一貫性のあるレベルまで状態を再構築するために、これまでに見たすべてのデータを再処理する必要がある。

しかし、チェックポイントは無料ではなく、チェックポイント・データを維持するために必要なストレージや、この繰り返し操作がアプリケーションのパフォーマンスに与える影響など、ストリーミング・アプリケーションに新たな要件を課すことになる。

この章では、Spark Streamingアプリケーションでチェックポイントをセットアップし、使用するために必要な考慮事項について説明する。 まず、プログラムでチェックポイントをセットアップする実用的な側面を例で説明する。 その後、チェックポイントから回復する方法、チェックポイントがもたらす演算子、そして最後に、チェックポイントのパフォーマンスを調整するテクニックについて説明する。

チェックポイントの使い方を理解する

、オンラインビデオストアで1時間あたりに再生されたビデオの回数を追跡する、以下のストリーミングジョブを考えてみよう。mapWithState を使って、ストリームを通過してくるvideoPlayed イベントを追跡し、イベントに埋め込まれたタイムスタンプを処理して、時間ベースの集計を決定する。

以下のコード・スニペットでは、次のように仮定している:

  • データストリームは以下の構造からなる。VideoPlayed(video-id, client-id, timestamp)

  • videoPlayedDStreamDStream[VideoPlayed]

  • このシグネチャーを持つtrackVideoHits 関数がある:

// Data Structures
case class VideoPlayed(videoId: String, clientId: String, timestamp: Long)
case class VideoPlayCount(videoId: String, day: Date, count: Long)

// State Tracking Function
def trackVideoHits(videoId: String,
                   timestamp:Option[Long],
                   runningCount: State[VideoPlayCount]
                   ): Option[VideoPlayCount]

オンラインリソース

チェックポインティングを理解するために必要な要素にコードを絞り込んだ。完全な例を調べるには、この本のオンラインリソース ...

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

Apache Flinkによるストリーム処理

Apache Flinkによるストリーム処理

Fabian Hueske, Vasiliki Kalavri

Publisher Resources

ISBN: 9798341650602