The document provides an introduction to the LMAX Disruptor, a data structure for high performance inter-thread messaging. It describes the Disruptor as allowing very fast message passing without contention by using a lock-free data structure called a ring buffer. The workshop covers the basic components of the Disruptor including the publisher, event handlers, and batch processing. It includes exercises to demonstrate wiring up a simple Disruptor configuration, adding parallel event handlers, and managing dependencies between handlers. Real-world uses like high throughput financial applications are also discussed.
1 of 80
Download to read offline
More Related Content
Workshop: Introduction to the Disruptor
1. An Introduction to the
LMAX Disruptor
Trisha Gee, Developer at LMAX Exchange
@trisha_gee
mechanitis.blogspot.com
Tuesday, 25 September 12
4. The Workshop
• Introduction to the Disruptor
• Simplest Case
• Performance Results
• Going Parallel
• The Real World
• Questions
Tuesday, 25 September 12
5. What is The Disruptor?
• Very fast message passing
• Data structure and work flow without
contention
• Allows you to go truly parallel
Tuesday, 25 September 12
48. TODO
• Print status of the enemy when the tower
sees it
• Print status of enemy after the tower
shoots it
• Shoot all enemies
Tuesday, 25 September 12
49. Task Breakdown
• Wire up the EventTranslator &
EventHandler, using the Disruptor class
• Implement shootAt
• Implement respawn & isDead
• Get unit tests to pass
• (check out mechanitis.examples.disruptor)
Tuesday, 25 September 12
50. Exercise One Goals
1. Understand the roles of Translators and
Event Handlers
2. Understand how to wire up a simple
Disruptor configuration
3. Understand how to get events flowing
through the Disruptor
Tuesday, 25 September 12
51. Performance vs a
Queue
Mac Air, 1.7GHz Core i5:
run 0: BlockingQueue=3,390,060 Disruptor=69,108,500 ops/sec
run 1: BlockingQueue=5,229,851 Disruptor=71,123,755 ops/sec
run 2: BlockingQueue=4,303,481 Disruptor=65,530,799 ops/sec
Disruptor - Time Taken: 3,242 millis
Disruptor - Time Taken: 3,319 millis
Disruptor - Time Taken: 4,045 millis
Queue - Time Taken: 30,022 millis
Queue - Time Taken: 31,823 millis
Queue - Time Taken: 29,280 millis
Tuesday, 25 September 12
52. Exercise Two
One publisher, two parallel event handlers
Tuesday, 25 September 12
55. • Make each enemy unique
• Write the details of each enemy generated
into a text file
Tuesday, 25 September 12
56. Task Breakdown
• Add randomness to enemy (e.g. give them a
speed to travel at)
• Wire in the EnemyLogger
• Implement describeTo in enemy
Tuesday, 25 September 12
57. Exercise Two Goals
1. Understand that EventHandlers can
process in parallel
2. Understand how to wire up EventHandlers
in parallel
3. Understand the caveats to going parallel -
single writer principal
Tuesday, 25 September 12
58. Exercise Three
Diamond Dependencies
Tuesday, 25 September 12
62. • Don’t use the Disruptor Wizard for
configuration
• Record results of the game to a different
text file
• Optional: add variability to Turret
Tuesday, 25 September 12
63. Task Breakdown
• Remove use of Disruptor.java and wire up
manually (mechanitis.examples.disruptor)
• Wire in ResultHandler
• Add missing things from Enemy class
Tuesday, 25 September 12
64. Exercise Three Goals
1. Understand sequence barriers
2. Understand different dependency
configurations
3. Understand wiring up without the wizard
Tuesday, 25 September 12