In our (LMAX's) case the producer writes the incoming bytes that represent a raw event into one field in a "message" object stored in the ring buffer. The unmarshalling event handler reads these bytes and translates them into a more usable form for the business logic, which it writes back to another, different, field (or fields) in the same "message" object.
When the marshaller, and other event handlers are finished, the business-logic event handler will call the appropriate method with the arguments. So the single-writer principle is preserved.
Dave Farley
The flippant answer: "Use a messaging bus". We use Ultra Messaging
from Informatica, I've also heard good things about ØMQ. We let the
messaging bus deal with ordering and fragmentation. We add our own
reliability and late join support using the disruptor. The basic
premise is to sequence all of the packets coming across the network
and re-request any that are missed. We use the ring buffer as a store
for messages on the publishing side. If we miss a message we can
rewind the event handler to the missed message and redeliver.
Mike.
We create a new object for each event. Object pooling is a technique
that I'd only apply with the utmost care. It can create more problems
that it fixes. Note that the information in Martin Fowler's article
is now a bit out of date. We un-marshal on the same thread as the
business logic. It's simpler and has very little performance impact.
It also gives the JVM a chance to apply escape analysis and
potentially allocate the business event on the stack. After a couple
of conversations with experts in the VM area it was suggested that
this is friendlier to the GC than allocating an object on one thread
passing it to another and nulling it out quickly afterward.
However, I don't consider our solution to be the most optimal. There
is a zero garbage approach that I demonstrated at Devoxx this year.
I'm going to put up some example code as soon as I get it packaged
cleanly.
Mike.
No problem, I've posted my most recent slides from Devoxx and JAX on my blog:
http://bad-concurrency.blogspot.com/2012/02/slides-from-recent-presentations.html
Mike.
Our messaging is topic based, i.e. pub/sub. Topics that we have
designated as reliable, will have a second associated topic, suffixed
with the string "_nak". A separate listener to the nak topic will
perform the rewind activity as required.
Mike.
Quite well described.best regards,Daniel
2012/2/25 Michael Barker
> Can you please give more details about the messaging layer and how the
Thanks for reply., Mike.
Do you keep (queue) messages in the same java process or delegate to a 3rd party (middleware) ?