Disruptor 中的并行生产者(环形缓冲区)(在 log4j2 中使用)
这样我就明白了LMX Disruptor算法(在log4j2中使用)的用途。我的问题是为什么生产者不能并行写入环形缓冲区中的多个插槽。为什么我们需要一个写指针,因为下一个序列生成器正在为不同的进程分配递增的数字。据我所知,序列化写入(和写入指针)可以帮助消费者了解最多可以读取哪个插槽。这是唯一的原因吗?
So I understand the purpose of the LMX Disruptor algorithm (used in log4j2). My question is why can’t producers just write to multiple slots in the ring buffer in parallel. Why do we need a write pointer, since next sequence generator is assigning incrementing numbers to different processes. I understand that serialising writes (and write pointers), helps consumers to know up to which slot can be read. Is that the only reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何防止多个生产者写入同一个槽?
假设您使用的是 MultiProducerSequencer,单个生产者可以通过调用 next(int) 写入多个槽,并且多个并行生产者显然可以在单个槽中并行写入槽(
next()
) 或批量 (next(int)
)。How would you prevent multiple producers from writing into the same slot?
Asuming you are using the
MultiProducerSequencer
, a single producer can write into multiple slots by callingnext(int)
and multiple parallel producers can obviously write into slots in parallel either in single slots (next()
) or batches (next(int)
).