Successfully reported this slideshow.

Concurrent Programming Using The Disruptor - Copenhagen

13

Share

Loading in …3
×
1 of 102
1 of 102

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Concurrent Programming Using The Disruptor - Copenhagen

  1. 1. Concurrent Programming Using The Disruptor Trisha Gee LMAX Wednesday, 23 May 12
  2. 2. Concurrent Programming Using The Disruptor Trisha Gee, Developer at LMAX @trisha_gee mechanitis.blogspot.com Wednesday, 23 May 12
  3. 3. The Disruptor? Wednesday, 23 May 12
  4. 4. What I’m covering • Overview of the Disruptor • Create your own! • Turn it up to Eleven • Q&A Wednesday, 23 May 12
  5. 5. 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
  6. 6. So...? Wednesday, 23 May 12
  7. 7. The Magic RingBuffer Wednesday, 23 May 12
  8. 8. The Magic RingBuffer Wednesday, 23 May 12
  9. 9. The Magic RingBuffer Wednesday, 23 May 12
  10. 10. The Magic RingBuffer Wednesday, 23 May 12
  11. 11. The Magic RingBuffer Wednesday, 23 May 12
  12. 12. The Magic RingBuffer Wednesday, 23 May 12
  13. 13. The Magic RingBuffer Wednesday, 23 May 12
  14. 14. Creating a RingBuffer final RingBuffer<SimpleEvent> ringBuffer = new RingBuffer<SimpleEvent>(SimpleEvent.EVENT_FACTORY, RING_BUFFER_SIZE); Wednesday, 23 May 12
  15. 15. The Events are Buckets Wednesday, 23 May 12
  16. 16. 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
  17. 17. I’ve got a RingBuffer! • Erm.... how do I poke things into it? Wednesday, 23 May 12
  18. 18. The Publisher Wednesday, 23 May 12
  19. 19. Wednesday, 23 May 12
  20. 20. Wednesday, 23 May 12
  21. 21. Wednesday, 23 May 12
  22. 22. Wednesday, 23 May 12
  23. 23. Wednesday, 23 May 12
  24. 24. Wednesday, 23 May 12
  25. 25. What do I do? public class SimpleEventTranslator implements EventTranslator<SimpleEvent> SimpleEventTranslator translator = new SimpleEventTranslator(); EventPublisher<SimpleEvent> publisher = new EventPublisher<SimpleEvent>(ringBuffer); // poke your translator here // ...and when you’re done... publisher.publishEvent(translator); Wednesday, 23 May 12
  26. 26. ...so now I want to read • The Disruptor provides nice batching behaviour for free Wednesday, 23 May 12
  27. 27. Wednesday, 23 May 12
  28. 28. Wednesday, 23 May 12
  29. 29. Wednesday, 23 May 12
  30. 30. Wednesday, 23 May 12
  31. 31. Wednesday, 23 May 12
  32. 32. Wednesday, 23 May 12
  33. 33. Wednesday, 23 May 12
  34. 34. Wednesday, 23 May 12
  35. 35. Wednesday, 23 May 12
  36. 36. Wednesday, 23 May 12
  37. 37. Wednesday, 23 May 12
  38. 38. Wednesday, 23 May 12
  39. 39. Wednesday, 23 May 12
  40. 40. Wednesday, 23 May 12
  41. 41. Wednesday, 23 May 12
  42. 42. ...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
  43. 43. Shiny. So what? Wednesday, 23 May 12
  44. 44. Let’s go parallel Wednesday, 23 May 12
  45. 45. And now for something different... Wednesday, 23 May 12
  46. 46. Remember Henry Ford? Wednesday, 23 May 12
  47. 47. Wednesday, 23 May 12
  48. 48. Wednesday, 23 May 12
  49. 49. Wednesday, 23 May 12
  50. 50. Wednesday, 23 May 12
  51. 51. Wednesday, 23 May 12
  52. 52. Wednesday, 23 May 12
  53. 53. Wednesday, 23 May 12
  54. 54. Complex workflow... Wednesday, 23 May 12
  55. 55. What on Earth has this got to do with RingBuffers?! Wednesday, 23 May 12
  56. 56. Wednesday, 23 May 12
  57. 57. Wednesday, 23 May 12
  58. 58. Wednesday, 23 May 12
  59. 59. Wednesday, 23 May 12
  60. 60. Wednesday, 23 May 12
  61. 61. Wednesday, 23 May 12
  62. 62. Wednesday, 23 May 12
  63. 63. Wednesday, 23 May 12
  64. 64. Wednesday, 23 May 12
  65. 65. Wednesday, 23 May 12
  66. 66. Wednesday, 23 May 12
  67. 67. Wednesday, 23 May 12
  68. 68. Wednesday, 23 May 12
  69. 69. Wednesday, 23 May 12
  70. 70. Wednesday, 23 May 12
  71. 71. Wednesday, 23 May 12
  72. 72. Wednesday, 23 May 12
  73. 73. Wednesday, 23 May 12
  74. 74. Wednesday, 23 May 12
  75. 75. Wednesday, 23 May 12
  76. 76. Wednesday, 23 May 12
  77. 77. Wednesday, 23 May 12
  78. 78. Wednesday, 23 May 12
  79. 79. Wednesday, 23 May 12
  80. 80. Wednesday, 23 May 12
  81. 81. Wednesday, 23 May 12
  82. 82. Wednesday, 23 May 12
  83. 83. Wednesday, 23 May 12
  84. 84. Wednesday, 23 May 12
  85. 85. Wednesday, 23 May 12
  86. 86. Wednesday, 23 May 12
  87. 87. Wednesday, 23 May 12
  88. 88. Wednesday, 23 May 12
  89. 89. Wednesday, 23 May 12
  90. 90. Wednesday, 23 May 12
  91. 91. Wednesday, 23 May 12
  92. 92. Wednesday, 23 May 12
  93. 93. Don’t wrap the buffer! ringBuffer.setGatingSequences(finalEventProcessor.getSequence()); Wednesday, 23 May 12
  94. 94. Caveats Wednesday, 23 May 12
  95. 95. 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
  96. 96. 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
  97. 97. More Information • Google Code Site, including Wiki http://code.google.com/p/disruptor/ • Blogs, e.g. mine: mechanitis.blogspot.com • Presentations • Google Group Wednesday, 23 May 12
  98. 98. Q&A Wednesday, 23 May 12
  99. 99. WorkerPool Wednesday, 23 May 12
  100. 100. AggregateEventHandler Wednesday, 23 May 12
  101. 101. WaitStrategies • BlockingWaitStrategy • BusySpinWaitStrategy • SleepingWaitStrategy • YieldingWaitStrategy Wednesday, 23 May 12
  102. 102. ClaimStrategies • SingleThreadedClaimStrategy • MultiThreadedClaimStrategy • MultiThreadedLowContentionClaimStrategy Wednesday, 23 May 12

×