concurrent programming using the disruptor - copenhagen

Post on 17-May-2015

5.637 Views

Category:

Technology

6 Downloads

Preview:

Click to see full reader

DESCRIPTION

The version of my Disruptor talk given at GOTO Copenhagen

TRANSCRIPT

Concurrent Programming Using The Disruptor

Trisha GeeLMAX

Wednesday, 23 May 12

Concurrent Programming Using The Disruptor

Trisha Gee, Developer at LMAX@trisha_gee

mechanitis.blogspot.com

Wednesday, 23 May 12

The Disruptor?

Wednesday, 23 May 12

What I’m covering

• Overview of the Disruptor

• Create your own!

• Turn it up to Eleven

• Q&A

Wednesday, 23 May 12

What is it?

• Data structure and work flow with no contention.

• Very fast message passing.

• Allows you to go truly parallel.

Wednesday, 23 May 12

So...?

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

The Magic RingBuffer

Wednesday, 23 May 12

Creating a RingBuffer

final RingBuffer<SimpleEvent> ringBuffer = new RingBuffer<SimpleEvent>(SimpleEvent.EVENT_FACTORY, RING_BUFFER_SIZE);

Wednesday, 23 May 12

The Events are Buckets

Wednesday, 23 May 12

Great! I want one!

public class SimpleEvent { public static final EventFactory<SimpleEvent> EVENT_FACTORY = new SimpleEventFactory();

private volatile String value;

private static class SimpleEventFactory implements EventFactory<SimpleEvent> { @Override public SimpleEvent newInstance() { return new SimpleEvent(); } } }

Wednesday, 23 May 12

I’ve got a RingBuffer!

• Erm.... how do I poke things into it?

Wednesday, 23 May 12

The Publisher

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

What do I do?

SimpleEventTranslator translator = new SimpleEventTranslator();

EventPublisher<SimpleEvent> publisher = new EventPublisher<SimpleEvent>(ringBuffer);

// poke your translator here// ...and when you’re done...publisher.publishEvent(translator);

public class SimpleEventTranslator implements EventTranslator<SimpleEvent>

Wednesday, 23 May 12

...so now I want to read

• The Disruptor provides nice batching behaviour for free

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

...and all you need is...

public class SimpleEventHandler implements EventHandler<SimpleEvent> { @Override public void onEvent(final SimpleEvent event, final long sequence, final boolean endOfBatch) throws Exception { // do stuff } }

Wednesday, 23 May 12

Shiny. So what?

Wednesday, 23 May 12

Let’s go parallel

Wednesday, 23 May 12

And now for something different...

Wednesday, 23 May 12

Remember Henry Ford?

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Complex workflow...

Wednesday, 23 May 12

What on Earth has this got to do with RingBuffers?!

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Wednesday, 23 May 12

Don’t wrap the buffer!

ringBuffer.setGatingSequences(finalEventProcessor.getSequence());

Wednesday, 23 May 12

Caveats

Wednesday, 23 May 12

Is that it?

• Wait and claim strategies

• Batch publishing

• Multiple publishers

• Different EventHandlers

• The Wizard

• You don’t even need a RingBuffer...

Wednesday, 23 May 12

You get...

• A framework the encourages you to model your domain

• The ability to run in parallel but single-threaded

• Reliable ordering

• ...and it can be very fast

Wednesday, 23 May 12

More Information

• Google Code Site, including Wikihttp://code.google.com/p/disruptor/

• Blogs, e.g. mine: mechanitis.blogspot.com

• Presentations

• Google Group

Wednesday, 23 May 12

Q&A

Wednesday, 23 May 12

WorkerPool

Wednesday, 23 May 12

AggregateEventHandler

Wednesday, 23 May 12

WaitStrategies

• BlockingWaitStrategy

• BusySpinWaitStrategy

• SleepingWaitStrategy

• YieldingWaitStrategy

Wednesday, 23 May 12

ClaimStrategies

• SingleThreadedClaimStrategy

• MultiThreadedClaimStrategy

• MultiThreadedLowContentionClaimStrategy

Wednesday, 23 May 12

top related