谷歌云数据工程师考试 - Cloud Pub/Sub 复习笔记

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 自动有
Batch data: timestamp需要手动加


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

系统自动learn的,不需要设定

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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,102评论 0 10
  • 01. 烦恼的根源都在自己 生气,是因为你不够大度; 郁闷,是因为你不够豁达; 焦虑,是因为你不够从容; 悲伤,是...
    馬荣軍阅读 583评论 0 0
  • 结束只是刚刚的开始 这两天有点忙,忙什么呢?忙着做几年前因为多方考虑而放弃的事。 可能我反复的说感谢行动营,你们或...
    践行者阿兰阅读 62评论 0 0
  • 国家:阶级统治的工具。爱国=爱工具;爱工具就会为工具付出,为国家好。所以,国家好了,统治阶级也就好了。由此能得出结...
    理论杀猪匠阅读 414评论 0 0
  • 已是四月中旬仲春时节了。来西安采风五天,却已下了两天的雨。雨的到来冲刷了初到西安时的炎热与干燥,反而有一种乍暖还寒...
    尤克养了一只猫阅读 330评论 0 4