Java 为什么Hazelcast IMap杂志不能产生所有预期的事件?
下面的最小工作示例fast生成事件,然后更新IMap。IMap进而从其日志生成更新事件Java 为什么Hazelcast IMap杂志不能产生所有预期的事件?,java,hazelcast,hazelcast-jet,Java,Hazelcast,Hazelcast Jet,下面的最小工作示例fast生成事件,然后更新IMap。IMap进而从其日志生成更新事件 公共类示例{ 组的私有静态最终整数=10; 私有静态最终整数事件数=1000; 公共静态void main(字符串[]args){ JetInstance jet=jet.newJetInstance(); IMap groups=jet.getMap(“组”); Pipeline p1=Pipeline.create(); p1.读取(fastStreamOfLongs(事件数)) .无时间戳() .wri
公共类示例{
组的私有静态最终整数=10;
私有静态最终整数事件数=1000;
公共静态void main(字符串[]args){
JetInstance jet=jet.newJetInstance();
IMap groups=jet.getMap(“组”);
Pipeline p1=Pipeline.create();
p1.读取(fastStreamOfLongs(事件数))
.无时间戳()
.writeTo(Sinks.mapWithUpdate(组、,
事件->事件组的%u数量,
(旧状态,事件)->增量(旧状态)
));
Pipeline p2=Pipeline.create();
p2.readFrom(Sources.mapJournal(组,从最早的开始)
.withIngestionTimestamps()
.map(x->x.getKey()+“->”+x.getValue())
.writeTo(Sinks.logger());
杰特·纽约伯(p2);
jet.newJob(p1.join();
}
私有静态StreamSource fastStreamOfLongs(int numberOfEvents){
返回源代码生成器
.stream(“快速龙”,ctx->new AtomicLong(0))
.fillBufferFn((num,buf)->{
long val=num.getAndIncrement();
如果(val
示例输出:
3 -> 7
3 -> 50
3 -> 79
7 -> 42
...
6 -> 100
0 -> 82
9 -> 41
9 -> 100
我希望看到1000个事件描述每个更新。相反,我看到大约50-80个事件。(输出似乎包含每个组的所有最新更新(即“->100”
),但除此之外,它是一个随机子集。)
当组的数量等于事件的数量时(或者当事件生成被人为减慢时),我收到所有1000次更新
这种行为是预期的吗?是否可以从fast源接收所有更新事件?
接收器。MapWithUpdate
使用批处理,因此在发送实际的更新条目处理器之前,一些更新会在本地应用。您需要使用Sinks.mapWithEntryProcessor
为每个项目发送更新条目处理器。
从Sinks.mapWithEntryProcessor的JavaDoc中:
* As opposed to {@link #mapWithUpdating} and {@link #mapWithMerging},
* this sink does not use batching and submits a separate entry processor
* for each received item. For use cases that are efficiently solvable
* using those sinks, this one will perform worse. It should be used only
* when they are not applicable.
请记住,事件日志的默认容量为10K,如果使用默认分区计数,则每个分区的容量为36,这不足以一次存储所有更新。对于您的情况,如果使用默认分区计数,则需要将容量设置为271K或更高以存储所有更新。我可以确认,在将方法更改为Sinks.mapWithEntryProcessor
并增加事件日志的容量后,我收到了所有更新。