Reputation: 39
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.
Upvotes: 0
Views: 267
Reputation: 2044
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.
Upvotes: 2
Reputation: 116
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?
Upvotes: 2
Reputation: 1326
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
.
Upvotes: 0