aeron icon indicating copy to clipboard operation
aeron copied to clipboard

[Cpp] Added tryClaim method to concurrent ringbuffers.

Open im95able opened this issue 2 years ago • 5 comments

In the codebase my team is working on we would like to use concurrent::ringbuffers. For us, tryClaim interface is preferred. I tried following you're code convetion as much as possible but reused the tryClaim implementaion for write methods(that way tryClaim also gets tested with write). Unfortunately order of atomic writes for oneToOneRingBuffer was changed. Tail gets written first and only after does messageHeader get written. This could affect performance. In our implementation of spsc channel we provide the callback to the tryClaim method which gets called with the claimed buffer. That way tail gets written after the messageHeader; wanting to stay within the convention of your codebase this PR does it by introducing RingBufferClaim class.

Edit: As per @mjpt777's suggestion refactored the code to reflect Java RingBuffers.

im95able avatar May 24 '22 12:05 im95able

It would be best if the implementations followed the same API semantics as we have for the Java RingBuffers.

https://github.com/real-logic/agrona/tree/master/agrona/src/main/java/org/agrona/concurrent/ringbuffer

mjpt777 avatar May 31 '22 13:05 mjpt777

It would be best if the implementations followed the same API semantics as we have for the Java RingBuffers.

https://github.com/real-logic/agrona/tree/master/agrona/src/main/java/org/agrona/concurrent/ringbuffer

Will do

im95able avatar Jun 08 '22 11:06 im95able

@mjpt777 could there be a review of this ?

im95able avatar Jun 22 '22 09:06 im95able

There are two things that stand out:

  • Usage of the RecordDescriptor::makeHeader to combine length and type fields together. We have decided that it would be better if the C++ version was aligned with the Java and C implementations, i.e. it should read/write length and type as separate fields.
  • OneToOneRingBuffer::claimCapacity is not aligned with the Java implementation, i.e. in Java and in C we add an additional HEADER_LENGTH when computing the requiredCapacity. This allows for pre-zeroing of the next header upon claim and thus we don't need to zero the memory in the read/controlledRead methods.

Another thing to note is that the C++ and C implementations don't have the controlledRead API.

Will fix this probably some time next week. Thanks for the input.

im95able avatar Jul 12 '22 08:07 im95able

Is this progressing?

mjpt777 avatar Aug 19 '22 14:08 mjpt777