Why my Disruptor program don't take full advantage of the ringbuffer

£可爱£侵袭症+ 提交于 2019-12-02 04:09:21

This is because the Disruptor will batch in the event handler. If the event handler is slow or the ring buffer is small the batch size can often be the size of the ring buffer. The Disruptor will only update the processed sequence for that event handler until the batch is complete. This reduces the number of updates that it needs to make to the sequence variable used by the publisher to determine if space is available. If you need to make space available earlier than the default then you can do that using a SequenceReportingEventHandler.

public class MyEventHandler implements SequenceReportingEventHandler<Element> {
    Sequence processedSequence;

    public void setSequenceCallback(Sequence s) {
        processedSequence = s;
    }

    public void onEvent(Element e, long sequence, boolean endOfBatch) {
        // Do stuff
        processedSequence.set(sequence);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!