简体   繁体   中英

How is LMAX Disruptor garbage collector friendly

I am trying to understand how lmax disruptor is GC friendly. I see that the event objects on the ring are re-used, however, the "data" that is "set" on these objects are on the heap so it feels like the garbage collection benefit is limited to 1 object less per event. if the 'data' is of primitive data type then there's nothing additional on the heap, so the benefit in this case is very clear. Is 1 object less to GC per event significant or there's more to this than I understand wrt GC.

This article http://mechanitis.blogspot.com/2011/06/dissecting-disruptor-whats-so-special.html says the garbage collector has pretty much nothing to do here - this isnt very obvious to me, hence the question.

The ring buffer acts as a pool of objects - when you claim a sequence you can copy data into the event and when all the event handlers have finished processing the event will be returned to the ring buffer again.

The trick is make sure that you copy the data into the event and therefore that the event can hold all the different types of data you might want to communicate between the producers and consumers. If you simply allocate an object on the heap on the producer side and pass a reference to this object to the event then you will obviously not reduce the memory pressure on the GC at all.

Another approach is to have an event which is simply an offset into some off-heap memory which can be interpreted as different types of objects by using flyweights.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM