SlideShare a Scribd company logo
1 of 80
Download to read offline
An Introduction to the
                  LMAX Disruptor
                           Trisha Gee, Developer at LMAX Exchange
                                          @trisha_gee
                                      mechanitis.blogspot.com




Tuesday, 25 September 12
Laptop Setup... Go!



Tuesday, 25 September 12
The Disruptor?



Tuesday, 25 September 12
The Workshop
                   • Introduction to the Disruptor
                   • Simplest Case
                   • Performance Results
                   • Going Parallel
                   • The Real World
                   • Questions
Tuesday, 25 September 12
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
So...?



Tuesday, 25 September 12
The Magic RingBuffer




Tuesday, 25 September 12
The Magic RingBuffer




Tuesday, 25 September 12
The Magic RingBuffer




Tuesday, 25 September 12
The Magic RingBuffer




Tuesday, 25 September 12
The Magic RingBuffer




Tuesday, 25 September 12
The Magic RingBuffer




Tuesday, 25 September 12
The Events are Buckets




Tuesday, 25 September 12
I’ve got a RingBuffer!


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



Tuesday, 25 September 12
The Publisher




Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
...so now I want to read


                   • The Disruptor provides nice batching
                           behaviour for free




Tuesday, 25 September 12
BatchEventProcessor




Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
The Problem



Tuesday, 25 September 12
Tower Defence?




Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Exercise One
                           One publisher, one event handler




Tuesday, 25 September 12
Our Problem




Tuesday, 25 September 12
Simplest Disruptor




Tuesday, 25 September 12
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
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
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
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
Exercise Two
                           One publisher, two parallel event handlers




Tuesday, 25 September 12
Let’s log all the enemies




Tuesday, 25 September 12
Parallel Processors




Tuesday, 25 September 12
• Make each enemy unique
                   • Write the details of each enemy generated
                           into a text file




Tuesday, 25 September 12
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
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
Exercise Three
                             Diamond Dependencies




Tuesday, 25 September 12
Recording the Results




Tuesday, 25 September 12
Sequence Barriers




Tuesday, 25 September 12
Managing Dependencies




Tuesday, 25 September 12
• 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
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
Exercise Three Goals

                   1. Understand sequence barriers
                   2. Understand different dependency
                      configurations
                   3. Understand wiring up without the wizard




Tuesday, 25 September 12
Exercise Four
                               Playtime!!




Tuesday, 25 September 12
Slow Consumers?




Tuesday, 25 September 12
The Real World



Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Ticket Purchasing




Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Tuesday, 25 September 12
Other Uses

                   • Queue replacement
                   • Single-threading your code
                   • Filtering
                   • Coalescing
                   • Dependency graphs

Tuesday, 25 September 12
Questions



Tuesday, 25 September 12

More Related Content

Similar to Workshop: Introduction to the Disruptor

Building Cordova plugins for iOS
Building Cordova plugins for iOSBuilding Cordova plugins for iOS
Building Cordova plugins for iOS
Grgur Grisogono
 
Make something real for Firefox OS with Mozilla app templates
Make something real  for Firefox OS with Mozilla app templatesMake something real  for Firefox OS with Mozilla app templates
Make something real for Firefox OS with Mozilla app templates
Piotr Zalewa
 
Symfony - Introduction
Symfony - IntroductionSymfony - Introduction
Symfony - Introduction
Piers Warmers
 

Similar to Workshop: Introduction to the Disruptor (12)

Reef - ESUG2011
Reef  - ESUG2011Reef  - ESUG2011
Reef - ESUG2011
 
Selenium Basics
Selenium BasicsSelenium Basics
Selenium Basics
 
Building Cordova plugins for iOS
Building Cordova plugins for iOSBuilding Cordova plugins for iOS
Building Cordova plugins for iOS
 
Make something real for Firefox OS with Mozilla app templates
Make something real  for Firefox OS with Mozilla app templatesMake something real  for Firefox OS with Mozilla app templates
Make something real for Firefox OS with Mozilla app templates
 
Architecting large Node.js applications
Architecting large Node.js applicationsArchitecting large Node.js applications
Architecting large Node.js applications
 
Capistrano
CapistranoCapistrano
Capistrano
 
Building Data Driven Products With Ruby - RubyConf 2012
Building Data Driven Products With Ruby - RubyConf 2012Building Data Driven Products With Ruby - RubyConf 2012
Building Data Driven Products With Ruby - RubyConf 2012
 
Node jsworkshop
Node jsworkshopNode jsworkshop
Node jsworkshop
 
Why can't organizations be designed as sexy as an iPad?
Why can't organizations be designed as sexy as an iPad?Why can't organizations be designed as sexy as an iPad?
Why can't organizations be designed as sexy as an iPad?
 
Scrum Master Role - Authority, Power and Leadership
Scrum Master Role - Authority, Power and LeadershipScrum Master Role - Authority, Power and Leadership
Scrum Master Role - Authority, Power and Leadership
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony Components
 
Symfony - Introduction
Symfony - IntroductionSymfony - Introduction
Symfony - Introduction
 

More from Trisha Gee

More from Trisha Gee (20)

Career Advice for Architects
Career Advice for Architects Career Advice for Architects
Career Advice for Architects
 
Is boilerplate code really so bad?
Is boilerplate code really so bad?Is boilerplate code really so bad?
Is boilerplate code really so bad?
 
Code Review Best Practices
Code Review Best PracticesCode Review Best Practices
Code Review Best Practices
 
Career Advice for Programmers - ProgNET London
Career Advice for Programmers - ProgNET LondonCareer Advice for Programmers - ProgNET London
Career Advice for Programmers - ProgNET London
 
Is Boilerplate Code Really So Bad?
Is Boilerplate Code Really So Bad?Is Boilerplate Code Really So Bad?
Is Boilerplate Code Really So Bad?
 
Real World Java 9 - JetBrains Webinar
Real World Java 9 - JetBrains WebinarReal World Java 9 - JetBrains Webinar
Real World Java 9 - JetBrains Webinar
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
Career Advice for Programmers
Career Advice for Programmers Career Advice for Programmers
Career Advice for Programmers
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
Becoming fully buzzword compliant
Becoming fully buzzword compliantBecoming fully buzzword compliant
Becoming fully buzzword compliant
 
Real World Java 9 (QCon London)
Real World Java 9 (QCon London)Real World Java 9 (QCon London)
Real World Java 9 (QCon London)
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and Tooling
 
Java 8 and 9 in Anger
Java 8 and 9 in AngerJava 8 and 9 in Anger
Java 8 and 9 in Anger
 
Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)
 
Migrating to IntelliJ IDEA from Eclipse
Migrating to IntelliJ IDEA from EclipseMigrating to IntelliJ IDEA from Eclipse
Migrating to IntelliJ IDEA from Eclipse
 
Code Review Matters and Manners
Code Review Matters and MannersCode Review Matters and Manners
Code Review Matters and Manners
 
Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)
 
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
 
Staying Ahead of the Curve
Staying Ahead of the CurveStaying Ahead of the Curve
Staying Ahead of the Curve
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Workshop: Introduction to the Disruptor