[英]Custom entities do not load within a Spring Cloud Dataflow Server
[英]Sort elements within a fixed window - Cloud Dataflow
我有一個數據流管道,該管道從pubsub主題讀取,執行轉換並寫入BigTable。 我希望從pubsub中讀取的元素按照其序列號的順序進行處理。
我正在使用2分鍾的固定窗口,然后在其上應用GroupByKey。 在GBK之后,我使用了SortValues轉換,該轉換對SequenceNumber上的Iterable進行排序。 我觀察到GroupByKey步驟的耗時很長,因為窗口中的所有元素都是在同一worker上處理的。 有沒有一種在固定窗口內對元素進行排序的有效方法?
以下是我的管道代碼:
PCollection<PubsubMessage> pubsubRecords = p.apply(PubsubIO.readMessagesWithAttributes()
.fromTopic(StaticValueProvider.of(topic)));
PCollection<KV<BigInteger, JSONObject>> window = pubsubRecords.apply("Raw to String", ParDo.of(new LogsFn()))
.apply("Window", Window
.<KV<BigInteger, JSONObject>>into(FixedWindows.of(Duration.standardMinutes(2)))
.triggering(Repeatedly
.forever(AfterProcessingTime
.pastFirstElementInPane()
.plusDelayOf(Duration.StandardMinutes(2))
)
)
.withAllowedLateness(Duration.ZERO).discardingFiredPanes()
);
PCollection<KV<String, KV<BigInteger, JSONObject>>> keyedWindow = window
.apply(WithKeys.of(new SerializableFunction<KV<BigInteger, JSONObject>,String>() {
@Override
public String apply(KV<BigInteger, JSONObject> row) {
return "key";
}
}));
PCollection<KV<String, Iterable<KV<BigInteger, JSONObject>>>> groupedWindow = keyedWindow
.apply(GroupByKey.<String, KV<BigInteger, JSONObject>>create()).apply(
SortValues.<String, BigInteger, JSONObject>create(BufferedExternalSorter.options()));
我認為您的方法是正確的。 不可避免的是,所有元素必須在同一工作程序中進行排序。 順序處理會在數據之間建立依賴關系,並且通常不適用於分布式計算。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.