1) Use a ring buffer of wrapper objects. My objects will just have a reference to a bytebuffer and an index into it. When a bytebuffer comes in on the network, my network thread will change the objects on the ring buffer to point to the bytebuffer and set the index appropriately. The consumer will process the payload(slices of the original bytebuffer) and set the bytebuffer reference to null. So when all slices get processed the bytebuffer should get GCed. Here I don't copy any of the bytebuffer contents. I have multiple references floating around, can't just reuse the original bytebuffer and might possibly incur the wrath of the GC gods. I also have some false sharing since I need to set the bytebuffer refs to null on the consumer.
2) Use a ring buffer of objects that have 3 longs. When a bytebuffer comes in, I can read it and copy the long fields onto ring buffer objects. The bytebuffer should get GCed or become available for reuse as soon as all the copying is done. I pay with copying but it's just 3 longs per object as opposed to a reference and an int in (1).
3) I create a specialized primitive friendly version of the ring buffer where I use a bytebuffer for my objects encoded in a way similar to the bytebuffer I receive on the network. When I get an incoming request i check to see find contiguous runs of data that needs to be sent to a single thread. I can then just do the memcpy equivalent of Java to copy from source to destination (might require Unsafe) and set the writer sequence appropriately. This is really like (2) except it is feeding into a single slab of memory instead of going through objects.
Of course benchmarking would be the right way to find out the best alternative. Any comments from experienced users/maintainers on the merits of each approach?
--
You received this message because you are subscribed to the Google Groups "Disruptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmax-disrupto...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.