Changing topology after starting

278 views
Skip to first unread message

Curtis Stanford

unread,
Sep 20, 2011, 12:53:12 PM9/20/11
to lmax-di...@googlegroups.com
Is it possible to add and remove consumers after disruptor has been started?

Martin Thompson

unread,
Sep 20, 2011, 1:10:01 PM9/20/11
to Disruptor
Curtis,

Yes this is possible. I've not done an example but this can be
achieved with the SequenceGroup.

If you get the RingBuffer/Sequencer to depend on the SequenceGroup you
can then add and remove event processors to the group rather than the
RingBuffer/Sequencer this will work. When you add them it is best to
set the EventProcessor sequence to the the current cursor value. This
method can generate some garbage and I'm considering other
implementations that could be garbage free.

Martin...

On Sep 20, 5:53 pm, Curtis Stanford <cur...@stanfordcomputing.com>
wrote:

Curtis Stanford

unread,
Sep 20, 2011, 1:36:52 PM9/20/11
to lmax-di...@googlegroups.com
Thanks Martin.

So, I've got something like:

Disruptor disruptor = new Disruptor<AsyncMessageEvent>(
new AsyncMessageEventFactory(),
30,
Executors.newCachedThreadPool(),
ClaimStrategy.Option.MULTI_THREADED,
WaitStrategy.Option.SLEEPING);
group = new SequenceGroup();
disruptor.getRingBuffer().setGatingSequences(group); // not sure about this
disruptor.start();

Now, how do I add more consumer handlers to the group? You can only add new Sequences to the SequenceGroup.

Martin Thompson

unread,
Sep 20, 2011, 6:19:44 PM9/20/11
to Disruptor
Hi,

The Disruptor is all about sequences :-)

Every EventProcessor has a getSequence() method. You can use this to
get the sequence of anything you need tracked. These can be added to
the group.

Martin...

On Sep 20, 6:36 pm, Curtis Stanford <cur...@stanfordcomputing.com>
wrote:

Martin Thompson

unread,
Sep 21, 2011, 5:31:53 AM9/21/11
to Disruptor
I've checked in a new implementation of SequenceGroup that is lock
free for add() and remove() and no longer creates an iterator when
get() is called.

This will make the next release.

Curtis Stanford

unread,
Sep 21, 2011, 12:34:57 PM9/21/11
to lmax-di...@googlegroups.com
Thanks a lot Martin. I look forward to any examples as well :)
Reply all
Reply to author
Forward
0 new messages