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 によるストリーム処理

第21章. 時間ベースのストリーム処理

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

、以前の変換で示したように、Spark Streamingは、時間ベースのデータ集約を構築する 機能を提供する。 Structured Streamingとは対照的に、この領域におけるSpark Streamingのアウトオブボックス機能は、 処理時間に限定される。「時間の効果」で思い出したように、これはストリーミングエンジンがイベントを処理する時間である。

この章では、Spark Streamingの様々なアグリゲーション機能について見ていく。 これらは処理時間領域に制約があるものの、豊富なセマンティクスを提供し、スケーラブルでリソースに制約のある方法でデータを処理するのに役立つ。

Windowsアグリゲーション

集約はストリームデータ処理で頻繁に見られるパターンであり、データのプロデューサ(入力側)とデータのコンシューマ(出力側)の関心の違いを反映している。

ウィンドウ集約 "で説明したように、時間の経過に伴うデータのウィンドウの概念は、大きな期間にまたがる集約を作成するのに役立つ。 Spark Streaming APIは、そのセクションで提示された2つの一般的なウィンドウ概念、タンブリング ウィンドウとスライディングウィンドウの定義を提供し、ウィンドウ上で演算する特殊化リデュース関数を提供することで、一定期間にわたって特定の集約を実行するのに必要な中間メモリの量を制限する。

次のページでは、Spark Streamingの ウィンドウ機能について説明する:

  • タンブリングウィンドウ

  • スライディングウィンドウ

  • Windowsベースの削減

タンブリング・ウインドウズ

Spark Streamingでは、最も基本的なウィンドウ定義は、DStreamsに対するwindow(<time>) 操作である。このDStream変換により、ウィンドウ化された新しいDStreamが作成され、このDStreamをさらに変換して目的の演算子を実装することができる。

ハッシュタグのDStreamを想定すると、タンブリング・ウィンドウでこれを行うことができる:

val tumblingHashtagFrequency = hashTags.window(Seconds(60))
                                       .map(hashTag => (hashTag,1))
                                       .reduceByKey(_ + _)

window の演算子では、mapreduceByKey のステップ(単純なカウントを行うことがわかっている)の前に、DストリームのセグメンテーションをRDDに再プログラムしている。元のストリーム、hashTags は、バッチ間隔に従った厳密なセグメンテーションに従っている:バッチごとに1つのRDD。

この場合、新しいDStream(hashTags.window(Seconds(60)) )は、60秒ごとに1つのRDDを含むように構成される。60秒が経過するたびに、新しいRDDがクラスタのリソース上に作成され、同じウィンドウDStreamの以前の要素とは独立する。その意味で、ウィンドウは「タンブリングウィンドウ」で説明したようにタンブリングしているすべてのRDDは、100%、ワイヤー上で読み取られた新しい「新鮮な」要素で構成される。

Windowsの長さとバッチ間隔の関係

窓付きストリームの作成は、元のストリームの複数のRDDの情報を、窓付きストリー ...

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