Apache Flink筆記

Apache Flink筆記原文鏈接http://timeyang.com/articles/28/2018/10/30/Apache%20Flink%20%E7%AC%94%E8%AE%B0

Apache Flink - Stateful Computations over Data Streams

Document

Apache Flink Documentation

Dataflow Model

The Dataflow Model: A Practical Approach to Balancing Correctness, Latency, and Cost in MassiveScale, Unbounded, OutofOrder Data Processing

State

Paper

  • Chandy-Lamport algorithm:Distributed Snapshots: Determining Global States of Distributed Systems

  • Lightweight Asynchronous Snapshots for Distributed Dataflows

    • an asynchronous snapshotting algorithm that achieves minimal snapshots on acyclic execution graphs

    • a generalisation of our algorithm that works on cyclic execution graphs

  • State Management in Apache Flink

    • a complete end-to-end design for continuous stateful processing, from the conceptual view of state in the programming model to its physical counterpart implemented in various backends.

    • how to naturally pipeline consistent snapshots in weakly connected dataflow graphs and capture minimal state, skipping in-transit records when possible, without impacting general system progress.

    • how snapshots can be utilized for a large variety of operational needs beyond failure recovery such as software patches, testing, system upgrades and exactly-once delivery.

    • encapsulate different processing guarantees and isolation levels for externally accessing partitioned operator state and output, using snapshots.

    • large-scale pipeline deployments that operate 24/7 in production and rely heavily on stateful processing coupled with runtime metrics and performance insights.

Article

Note

  1. Key-Groups

    • Key-Groups是flink重分發(fā)狀態(tài)的原子單元。

    • 使用一致性哈希算法減少seek和增加磁盤順序讀氏涩。

    • 實現(xiàn):先對key做hash,然后對最大并行度取模。以任務(wù)并行度等分哈希環(huán),每個task instance處理[ i * max_parallelism/parallelism, (i + 1) * max_parallelism/parallelism)內(nèi)的key目代,管理keyed-state蛤奥。如果并行度改變,則加載新的范圍的狀態(tài)忌卤,新進來的記錄也會哈希到持有對應(yīng)key的狀態(tài)的task instance

    • 為什么使用一致性哈希:如果不使用一致性哈希,比如使用并行度來取模楞泼。那么在并行度改變時驰徊,要么任務(wù)掃描整個快照,獲取指派給它的所有鍵的狀態(tài)堕阔,這會導(dǎo)致大量不必要的I/O棍厂;或者在快照中保存對每個key-state的引用,即索引超陆,這樣每個任務(wù)來選擇性地讀取指派給它的狀態(tài)牺弹,這會增加索引成本(與key的數(shù)量成比例,而key的數(shù)量可能會非常大)和通信負載时呀。使用一致性哈希张漂,則每個task實例只讀需要的數(shù)據(jù),而且通常Key-Groups足夠大以致能夠粗粒度地順序磁盤讀谨娜。

    • 注意哈希環(huán)即最大并行度不能夠設(shè)置的太大航攒。因為根據(jù)上面定義,Key-Groups數(shù)量與最大并行度相同趴梢,如果最大并行度設(shè)置得太大漠畜,則每個Key-Groups可能只由很少的key的狀態(tài)組成,從而無法進行粗粒度磁盤讀寫坞靶,導(dǎo)致性能降低憔狞。

  2. Rollback

    • During a full restart or rescaling, all tasks are being redeployed, while after a failure only the tasks belonging to the affected connected component (of the execution graph) are reconfigured.

    • In essence, known incremental recovery techniques from micro-batch processing are orthogonal to this approach and can also be employed. A snapshot epoch acts as synchronization point, similarly to a micro-batch or an input-split. On recovery, new task instances are being scheduled and, upon initialization, retrieve their allocated shard of state. In the case of IterationHead recovery, all records logged during the snapshot are recovered and flushed to output channels prior to their regular record forwarding logic.

  3. Asynchronous and Incremental Snapshots

    • the pipelined snapshotting protocol only governs “when” but not “how” snapshots are internally executed.

    • The out-of-core state backend based on RocksDB [13]exploits the LSM (log-structured merge) tree, internal representation of data in RocksDB. Updates are not made in-place, but are appended and compacted asynchronously. Upon taking a snapshot, the synchronous triggerSnapshot() call simply marks the current version, which prevents all state as of that version to be overwritten during compactions. The operator can then continue processing and make modifications to the state. An asynchronous thread iterates over the marked version, materializes it to the snapshot store, and finally releases the snapshot so that future compactions can overwrite that state. Furthermore, the LSM-based data structure also lends itself to incremental snapshots, which write only parts to the snapshot store that changed since the previous snapshots.

    • Flink’s in-memory local state backend implementation is based on hash tables that employ chain hashing. During a snapshot, it copies the current table array synchronously and then starts the external materialization of the snapshot, in a background thread. The operator’s regular stream processing thread lazily copies the state entries and overflow chains upon modification, if the materialization thread still holds onto the snapshot. Incremental snapshots for the in-memory local backend are possible and conceptually trivial (using delta maps), yet not implemented at the current point.

  4. ExactlyOnce Delivery Sinks

    • Idempotent Sinks

    • Transactional Sinks

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市彰阴,隨后出現(xiàn)的幾起案子瘾敢,更是在濱河造成了極大的恐慌,老刑警劉巖尿这,帶你破解...
    沈念sama閱讀 219,188評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件簇抵,死亡現(xiàn)場離奇詭異,居然都是意外死亡妻味,警方通過查閱死者的電腦和手機正压,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來责球,“玉大人焦履,你說我怎么就攤上這事拓劝。” “怎么了嘉裤?”我有些...
    開封第一講書人閱讀 165,562評論 0 356
  • 文/不壞的土叔 我叫張陵郑临,是天一觀的道長。 經(jīng)常有香客問我屑宠,道長厢洞,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,893評論 1 295
  • 正文 為了忘掉前任典奉,我火速辦了婚禮躺翻,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘卫玖。我一直安慰自己公你,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,917評論 6 392
  • 文/花漫 我一把揭開白布假瞬。 她就那樣靜靜地躺著陕靠,像睡著了一般。 火紅的嫁衣襯著肌膚如雪脱茉。 梳的紋絲不亂的頭發(fā)上剪芥,一...
    開封第一講書人閱讀 51,708評論 1 305
  • 那天,我揣著相機與錄音琴许,去河邊找鬼税肪。 笑死,一個胖子當(dāng)著我的面吹牛虚吟,可吹牛的內(nèi)容都是我干的寸认。 我是一名探鬼主播签财,決...
    沈念sama閱讀 40,430評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼串慰,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了唱蒸?” 一聲冷哼從身側(cè)響起邦鲫,我...
    開封第一講書人閱讀 39,342評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎神汹,沒想到半個月后庆捺,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,801評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡屁魏,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,976評論 3 337
  • 正文 我和宋清朗相戀三年滔以,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片氓拼。...
    茶點故事閱讀 40,115評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡你画,死狀恐怖抵碟,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情坏匪,我是刑警寧澤拟逮,帶...
    沈念sama閱讀 35,804評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站适滓,受9級特大地震影響敦迄,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜凭迹,卻給世界環(huán)境...
    茶點故事閱讀 41,458評論 3 331
  • 文/蒙蒙 一罚屋、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧嗅绸,春花似錦沿后、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至瞧柔,卻和暖如春漆弄,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背造锅。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評論 1 272
  • 我被黑心中介騙來泰國打工撼唾, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人哥蔚。 一個月前我還...
    沈念sama閱讀 48,365評論 3 373
  • 正文 我出身青樓倒谷,卻偏偏與公主長得像,于是被迫代替她去往敵國和親糙箍。 傳聞我的和親對象是個殘疾皇子渤愁,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,055評論 2 355

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,334評論 0 10
  • 1、藍湖篇 藍湖之藍深夯,果然名不虛傳抖格。宛如絲綢錦緞般華麗明艷、色澤飽滿的一汪湖水咕晋,在忽強忽暗的陽光映照下雹拄,不時變換出...
    水之晶閱讀 246評論 0 0
  • 單身宿舍買了鍋,剛好遇到發(fā)了粽子掌呜,某人于是開始花式表演
    taxedo閱讀 182評論 0 0
  • 今天是西洋的母親節(jié)滓玖,我很幸運地陪伴在她的身邊,帶她給她的媽媽送去問候质蕉。這是我的第二個母親節(jié)势篡∷鸾回想從懷孕到生產(chǎn),再到...
    李九_Lijiu閱讀 197評論 0 0
  • 一. 利用iOS開發(fā)工具Xcode 創(chuàng)建一個空項目; 二. 添加React-Native 依賴包 React Na...
    摸著_石頭過河閱讀 1,606評論 5 6