单例请求缓冲区上的 Aeron 发布端并发问题

发布于 2025-01-14 04:03:17 字数 107 浏览 4 评论 0原文

有没有最佳实践来处理发布端的并发? 假设我们有一个客户端想要处理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

站稳脚跟 2025-01-21 04:03:17

我假设您正在使用并发发布,这不是并发访问所遇到的问题。问题似乎是该优惠的共享缓冲区。要同时发布,您可以使用线程本地缓冲区来构造消息,或者如果消息长度小于 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 use Publication.tryClaim if the message length is less than MTU and construct the message using a thread local BufferClaim instance.

山川志 2025-01-21 04:03:17

这取决于 Publication 的创建方式,即 io.aeron.Aeron#addPublication 返回 ConcurrentPublication 类的实例,该实例作为顾名思义,可以由多个线程同时使用。另一方面,io.aeron.Aeron#addExclusivePublication 返回一个 ExclusivePublication 实例,该实例只能由单个线程使用。

@mohamadreza:为什么要使用单个共享的可扩展数组缓冲区?

It depends on how the Publication is being created, i.e. the io.aeron.Aeron#addPublication returns an instance of the ConcurrentPublication class which as the name suggest can be used by multiple threads concurrently. The io.aeron.Aeron#addExclusivePublication on the other hand returns an ExclusivePublication instance which can only be used by a single thread.

@mohamadreza: Why would you use a single shared expandable array buffer?

你的往事 2025-01-21 04:03:17

从问题的描述来看,您应该受益于使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文