谷歌云數(shù)據(jù)工程師考試 - Cloud Pub/Sub 復(fù)習(xí)筆記

https://cloud.google.com/pubsub/docs/ordering

Order in the final result matters

Typical Use Cases: Logs, state updates

In use cases in this category, the order in which messages are processed does not matter; all that matters is that the end result is ordered properly. For example, consider a collated log that is processed and stored to disk. The log events come from multiple publishers. In this case, the actual order in which log events are processed does not matter; all that matters is that the end result can be accessed in a time-sorted manner. Therefore, you could attach a timestamp to every event in the publisher and make the subscriber store the messages in some underlying data store (such as Cloud Datastore) that allows storage or retrieval by the sorted timestamp.

The same option works for state updates that require access to only the most recent state. For example, consider keeping track of current prices for different stocks where one does not care about history, only the most recent value. You could attach a timestamp to each stock tick and only store ones that are more recent than the currently-stored value.

Timestamp

Streaming data: timestamp 自動(dòng)有
Batch data: timestamp需要手動(dòng)加


Screen Shot 2018-07-10 at 11.22.44 pm.png

The timestamp is the basis of all windowing primitives including watermarks. Triggers and lag monitoring of delayed messages.

By default, the timestamp is set during the publishing process and represents the real time at which the message is published to pub-sub, which is a system time

There are cases where you want to override system time with your own-time stamp, you can use a custom timestamp by publishing it as a pub-sub attribute.

-> then you inform Dataflow using the timestamp label setter

Windowing

Windowing subdivides a PCollection according to the timestamps of its individual elements.

Watermark

系統(tǒng)自動(dòng)learn的兵怯,不需要設(shè)定

System’s notion of when all data in a certain window can be expected to have arrived in the pipeline. Data that arrives with a timestamp after the watermark is considered late data.

From our example, suppose we have a simple watermark that assumes approximately 30s of lag time between the data timestamps (the event time) and the time the data appears in the pipeline (the processing time), then Beam would close the first window at 5:30.

Beam’s default windowing configuration tries to determines when all data has arrived (based on the type of data source) and then advances the watermark past the end of the window. This default configuration does not allow late data.

You can allow late data by invoking the .withAllowedLateness operation when you set your PCollection’s windowing strategy.

PCollection<String> items = ...;
PCollection<String> fixedWindowedItems = items.apply(
Window.<String>into(FixedWindows.of(Duration.standardMinutes(1)))
.withAllowedLateness(Duration.standardDays(2)));

Triggers

To determine when to emit the aggregated results of each window

To handle late data

Batch data: add timestamp

1 Set window
2 (system self learn) watermark defines what is late data
3 Allow late data by invoking .withAllowedLateness operation
4 Set triggers to allow processing of late data by triggering after the event time watermark passes the end of the window.

Pub/Sub vs. Kafka

http://www.jesse-anderson.com/2016/07/apache-kafka-and-google-cloud-pubsub/

Cloud vs DIY
Pub/sub is on cloud vs. Kafka can be on-premise or in-cloud

Operations
-> Pub/Sub stores messages for seven days and can NOT configure to store more vs. Kafka can store as much data as you want (e.g. 4 - 21 days)
-> Pub/Sub automatically replicated to several regions and zones vs. Kafka requires self-replication
-> Pub/Sub has SLA uptime vs. Kafka is you purview
-> Pub/Sub has built-in authentication via Google Cloud’s IAM vs. Kafka has support for authentication (via Kerberos)
-> Pub/Sub encrypts line and at rest vs. Kafka at rest encryption is the responsibility of the user

Price
Pub/Sub is priced per million messages and for storage. publishing and consuming 10 million messages would cost $16

Architectural difference
-> Kafka gives options around delivery guarantees vs. Pub/Sub guarantees an at least once and you can’t change that programmatically
-> Both products feature massive scalability
-> Kafka does not guarantee performance (depending on configuration and partition) vs. Pub/Sub provides guaranteed performance
-> Kafka guarantees ordering in a partition vs. Pub/Sub does not have ordering guarantees.

How does Kafka guarantee order?

https://medium.com/@felipedutratine/kafka-ordering-guarantees-99320db8f87f

-> Use only one partition. Kafka preserves the order of messages within a partition.
-> set the config max.in.flight.requests.per.connection=1 to make sure that while a batch of messages is retrying, additional messages will not be sent
-> If multiple partitions: put all the messages with the same key on one partition.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末定躏,一起剝皮案震驚了整個(gè)濱河市梅猿,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌睦番,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,858評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異丐箩,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)恤煞,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,372評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門屎勘,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人居扒,你說(shuō)我怎么就攤上這事概漱。” “怎么了喜喂?”我有些...
    開封第一講書人閱讀 165,282評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵瓤摧,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我玉吁,道長(zhǎng)照弥,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,842評(píng)論 1 295
  • 正文 為了忘掉前任进副,我火速辦了婚禮这揣,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘影斑。我一直安慰自己给赞,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,857評(píng)論 6 392
  • 文/花漫 我一把揭開白布鸥昏。 她就那樣靜靜地躺著塞俱,像睡著了一般。 火紅的嫁衣襯著肌膚如雪吏垮。 梳的紋絲不亂的頭發(fā)上障涯,一...
    開封第一講書人閱讀 51,679評(píng)論 1 305
  • 那天罐旗,我揣著相機(jī)與錄音,去河邊找鬼唯蝶。 笑死九秀,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的粘我。 我是一名探鬼主播鼓蜒,決...
    沈念sama閱讀 40,406評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼征字!你這毒婦竟也來(lái)了都弹?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,311評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤匙姜,失蹤者是張志新(化名)和其女友劉穎畅厢,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體氮昧,經(jīng)...
    沈念sama閱讀 45,767評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡框杜,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,945評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了袖肥。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片咪辱。...
    茶點(diǎn)故事閱讀 40,090評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖椎组,靈堂內(nèi)的尸體忽然破棺而出油狂,到底是詐尸還是另有隱情,我是刑警寧澤庐杨,帶...
    沈念sama閱讀 35,785評(píng)論 5 346
  • 正文 年R本政府宣布选调,位于F島的核電站夹供,受9級(jí)特大地震影響灵份,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜哮洽,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,420評(píng)論 3 331
  • 文/蒙蒙 一填渠、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧鸟辅,春花似錦氛什、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,988評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至再层,卻和暖如春贸铜,著一層夾襖步出監(jiān)牢的瞬間堡纬,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,101評(píng)論 1 271
  • 我被黑心中介騙來(lái)泰國(guó)打工蒿秦, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留烤镐,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,298評(píng)論 3 372
  • 正文 我出身青樓棍鳖,卻偏偏與公主長(zhǎng)得像炮叶,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子渡处,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,033評(píng)論 2 355

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

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,332評(píng)論 0 10
  • 01. 煩惱的根源都在自己 生氣,是因?yàn)槟悴粔虼蠖龋?郁悶馁菜,是因?yàn)槟悴粔蚧磉_(dá)摹恨; 焦慮,是因?yàn)槟悴粔驈娜荩?悲傷茫孔,是...
    馬榮軍閱讀 605評(píng)論 0 0
  • 結(jié)束只是剛剛的開始 這兩天有點(diǎn)忙,忙什么呢被芳?忙著做幾年前因?yàn)槎喾娇紤]而放棄的事缰贝。 可能我反復(fù)的說(shuō)感謝行動(dòng)營(yíng),你們或...
    踐行者阿蘭閱讀 75評(píng)論 0 0
  • 國(guó)家:階級(jí)統(tǒng)治的工具畔濒。愛國(guó)=愛工具剩晴;愛工具就會(huì)為工具付出,為國(guó)家好侵状。所以赞弥,國(guó)家好了,統(tǒng)治階級(jí)也就好了趣兄。由此能得出結(jié)...
    理論殺豬匠閱讀 439評(píng)論 0 0
  • 已是四月中旬仲春時(shí)節(jié)了绽左。來(lái)西安采風(fēng)五天,卻已下了兩天的雨艇潭。雨的到來(lái)沖刷了初到西安時(shí)的炎熱與干燥拼窥,反而有一種乍暖還寒...
    尤克養(yǎng)了一只貓閱讀 360評(píng)論 0 4