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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
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
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
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
 

Workshop: Introduction to the Disruptor