单例请求缓冲区上的 Aeron 发布端并发问题
有没有最佳实践来处理发布端的并发? 假设我们有一个客户端想要处理 100 万个并发请求,这些请求必须通过发布报价发送到 Aeron 服务器端。现在我们有一个单例可扩展数组缓冲区,它会被并发覆盖并损坏。
is there any best practice to handle concurrency on publish side??
assume that we have a client that wants to handle 1 Million concurrent requests, these requests must send to the Aeron server-side via publication offer. now we have a singleton expandable array buffer that overwrites and is corrupted by concurrency.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您正在使用并发
发布
,这不是并发访问所遇到的问题。问题似乎是该优惠的共享缓冲区。要同时发布,您可以使用线程本地缓冲区来构造消息,或者如果消息长度小于 MTU,则可以使用Publication.tryClaim
并使用线程本地BufferClaim< 构造消息/代码> 实例。
I'm assuming you are using a concurrent
Publication
and that is not the issue you have with concurrent access. The issue seems to be a shared buffer for the offer. To publish concurrently you can have thread local buffers to construct your messages within, or you can usePublication.tryClaim
if the message length is less than MTU and construct the message using a thread localBufferClaim
instance.这取决于
Publication
的创建方式,即io.aeron.Aeron#addPublication
返回ConcurrentPublication
类的实例,该实例作为顾名思义,可以由多个线程同时使用。另一方面,io.aeron.Aeron#addExclusivePublication
返回一个ExclusivePublication
实例,该实例只能由单个线程使用。@mohamadreza:为什么要使用单个共享的可扩展数组缓冲区?
It depends on how the
Publication
is being created, i.e. theio.aeron.Aeron#addPublication
returns an instance of theConcurrentPublication
class which as the name suggest can be used by multiple threads concurrently. Theio.aeron.Aeron#addExclusivePublication
on the other hand returns anExclusivePublication
instance which can only be used by a single thread.@mohamadreza: Why would you use a single shared expandable array buffer?
从问题的描述来看,您应该受益于使用 https://github.com/real-logic/agrona/blob/master/agrona/src/main/java/org/agrona/concurrent/ringbuffer/ManyToOneRingBuffer.java 然后实现 MessageHandler利用
io.aeron.ExclusivePublication#offer
。From the description of the problem, you should benefit from using https://github.com/real-logic/agrona/blob/master/agrona/src/main/java/org/agrona/concurrent/ringbuffer/ManyToOneRingBuffer.java and then implement the MessageHandler that makes use of
io.aeron.ExclusivePublication#offer
.