gpt4 book ai didi

stream - Apache Kafka Streams 将 KTables 物化为主题似乎很慢

转载 作者:行者123 更新时间:2023-12-04 02:01:27 26 4
gpt4 key购买 nike

我正在使用 kafka 流,并且正在尝试将 KTable 物化为主题。

它有效,但似乎每 30 秒左右完成一次。

Kafka Stream 如何/何时决定将 KTable 的当前状态具体化为主题?

有什么办法可以缩短这个时间并使它更“实时”?

这是我正在使用的实际代码

// Stream of random ints: (1,1) -> (6,6) -> (3,3)
// one record every 500ms
KStream<Integer, Integer> kStream = builder.stream(Serdes.Integer(), Serdes.Integer(), RandomNumberProducer.TOPIC);

// grouping by key
KGroupedStream<Integer, Integer> byKey = kStream.groupByKey(Serdes.Integer(), Serdes.Integer());

// same behaviour with or without the TimeWindow
KTable<Windowed<Integer>, Long> count = byKey.count(TimeWindows.of(1000L),"total");

// same behaviour with only count.to(Serdes.Integer(), Serdes.Long(), RandomCountConsumer.TOPIC);
count.toStream().map((k,v) -> new KeyValue<>(k.key(), v)).to(Serdes.Integer(), Serdes.Long(), RandomCountConsumer.TOPIC);

最佳答案

这由 commit.interval.ms 控制,默认为 30 秒。更多细节在这里:
http://docs.confluent.io/current/streams/developer-guide.html

The semantics of caching is that data is flushed to the state store and forwarded to the next downstream processor node whenever the earliest of commit.interval.ms or cache.max.bytes.buffering (cache pressure) hits.



在这里:

https://cwiki.apache.org/confluence/display/KAFKA/KIP-63%3A+Unify+store+and+downstream+caching+in+streams

关于stream - Apache Kafka Streams 将 KTables 物化为主题似乎很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711499/

26 4 0