SlideShare a Scribd company logo
Concurrent Programming
  Using The Disruptor
    Trisha Gee, Developer at LMAX
               @trisha_gee
           mechanitis.blogspot.com
The Disruptor?
What I’m covering

• Overview of the Disruptor
• Create your own!
• Turn it up to Eleven
• Q&A
What is it?

• Data structure and work flow with no
  contention.
• Very fast message passing.
• Allows you to go truly parallel.
So...?
The Magic RingBuffer
The Magic RingBuffer
The Magic RingBuffer
The Magic RingBuffer
The Magic RingBuffer
The Magic RingBuffer
The Magic RingBuffer
Creating a RingBuffer

final RingBuffer<SimpleEvent> ringBuffer =
    new RingBuffer<SimpleEvent>(SimpleEvent.EVENT_FACTORY,
                                RING_BUFFER_SIZE);
The Events are Buckets
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();
        }
    }
}
I’ve got a RingBuffer!


• Erm.... how do I poke things into it?
The Publisher
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
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);
...so now I want to read


• The Disruptor provides nice batching
  behaviour for free
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
...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
    }
}
Shiny. So what?
Let’s go parallel
And now for something
      different...
Remember Henry
    Ford?
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Complex workflow...
What on Earth has this
   got to do with
    RingBuffers?!
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
Don’t wrap the buffer!

ringBuffer.setGatingSequences(finalEventProcessor.getSequence());
Caveats
Is that it?

• Wait and claim strategies
• Multiple publishers
• Different EventHandlers
• The Wizard
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
More Information

• Google Code Site, including Wiki
  http://code.google.com/p/disruptor/
• Blogs, e.g. mine: mechanitis.blogspot.com
• Presentations
• Google Group
Q&A


• We are hiring!
• careers@lmax.com

More Related Content

PDF
Introduction to the Disruptor
PPSX
LMAX Disruptor as real-life example
PPSX
LMAX Disruptor - High Performance Inter-Thread Messaging Library
KEY
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
PDF
LMAX Architecture
PDF
MariaDB MaxScale
PPTX
ELK Stack
PPT
Introduction to redis
Introduction to the Disruptor
LMAX Disruptor as real-life example
LMAX Disruptor - High Performance Inter-Thread Messaging Library
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
LMAX Architecture
MariaDB MaxScale
ELK Stack
Introduction to redis

What's hot (20)

PPT
High Frequency Trading and NoSQL database
PDF
ProxySQL at Scale on AWS.pdf
PDF
High Concurrency Architecture at TIKI
PDF
Grokking TechTalk #33: High Concurrency Architecture at TIKI
PDF
FIFA 온라인 3의 MongoDB 사용기
PPTX
Caching solutions with Redis
PPTX
PDF
Group Replication in MySQL 8.0 ( A Walk Through )
PDF
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
PPTX
Stability Patterns for Microservices
PPTX
Introduction to Redis
PPTX
MySQL Architecture and Engine
PDF
Best Practice for Achieving High Availability in MariaDB
PDF
MariaDB 10: The Complete Tutorial
PPTX
Asynchronous processing in big system
PPTX
Synchronous vs Asynchronous Programming
PDF
카프카, 산전수전 노하우
PDF
Using all of the high availability options in MariaDB
ODP
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
PPTX
Redis and it's data types
High Frequency Trading and NoSQL database
ProxySQL at Scale on AWS.pdf
High Concurrency Architecture at TIKI
Grokking TechTalk #33: High Concurrency Architecture at TIKI
FIFA 온라인 3의 MongoDB 사용기
Caching solutions with Redis
Group Replication in MySQL 8.0 ( A Walk Through )
[오픈소스컨설팅]Day #1 MySQL 엔진소개, 튜닝, 백업 및 복구, 업그레이드방법
Stability Patterns for Microservices
Introduction to Redis
MySQL Architecture and Engine
Best Practice for Achieving High Availability in MariaDB
MariaDB 10: The Complete Tutorial
Asynchronous processing in big system
Synchronous vs Asynchronous Programming
카프카, 산전수전 노하우
Using all of the high availability options in MariaDB
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
Redis and it's data types
Ad

Similar to Concurrent Programming Using the Disruptor (20)

PDF
Trisha gee concurrentprogrammingusingthedisruptor
PDF
Concurrent Programming Using The Disruptor - Copenhagen
PDF
Disruptor 2015-12-22 @ java.il
PPTX
Disruptor
PDF
Springone2gx 2014 Reactive Streams and Reactor
PDF
NIO MULTIPLEXER.pdf
PPTX
Event and signal driven programming
PDF
Designing for Distributed Systems with Reactor and Reactive Streams
PPTX
Reactive solutions using java 9 and spring reactor
PDF
Java under the hood
PDF
Stream Processing with CompletableFuture and Flow in Java 9
PDF
Workshop: Introduction to the Disruptor
PDF
Workshop: Event-sourced system through Reactive Streams
PPTX
Workshop: Event-sourced system through Reactive Streams
PPTX
Event and Signal Driven Programming Zendcon 2012
PDF
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
PDF
Spring 5 Webflux - Advances in Java 2018
PDF
Microservices with Spring 5 Webflux - jProfessionals
PPTX
Intro to Reactor
PPTX
PerfUG - Disruptor at ABC Arbitrage - March 2018
Trisha gee concurrentprogrammingusingthedisruptor
Concurrent Programming Using The Disruptor - Copenhagen
Disruptor 2015-12-22 @ java.il
Disruptor
Springone2gx 2014 Reactive Streams and Reactor
NIO MULTIPLEXER.pdf
Event and signal driven programming
Designing for Distributed Systems with Reactor and Reactive Streams
Reactive solutions using java 9 and spring reactor
Java under the hood
Stream Processing with CompletableFuture and Flow in Java 9
Workshop: Introduction to the Disruptor
Workshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive Streams
Event and Signal Driven Programming Zendcon 2012
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Spring 5 Webflux - Advances in Java 2018
Microservices with Spring 5 Webflux - jProfessionals
Intro to Reactor
PerfUG - Disruptor at ABC Arbitrage - March 2018
Ad

More from Trisha Gee (20)

PPTX
Career Advice for Architects
PPTX
Is boilerplate code really so bad?
PPTX
Code Review Best Practices
PDF
Career Advice for Programmers - ProgNET London
PDF
Is Boilerplate Code Really So Bad?
PPTX
Real World Java 9 - JetBrains Webinar
PDF
Real World Java 9
PPTX
Real World Java 9
PPTX
Career Advice for Programmers
PPTX
Real World Java 9
PPTX
Becoming fully buzzword compliant
PDF
Real World Java 9 (QCon London)
PPTX
Java 9 Functionality and Tooling
PDF
Java 8 and 9 in Anger
PDF
Refactoring to Java 8 (Devoxx BE)
PDF
Code Review Matters and Manners
PDF
Refactoring to Java 8 (QCon New York)
PDF
Refactoring to Java 8 (Devoxx UK)
PDF
Staying Ahead of the Curve
PPTX
Level Up Your Automated Tests
Career Advice for Architects
Is boilerplate code really so bad?
Code Review Best Practices
Career Advice for Programmers - ProgNET London
Is Boilerplate Code Really So Bad?
Real World Java 9 - JetBrains Webinar
Real World Java 9
Real World Java 9
Career Advice for Programmers
Real World Java 9
Becoming fully buzzword compliant
Real World Java 9 (QCon London)
Java 9 Functionality and Tooling
Java 8 and 9 in Anger
Refactoring to Java 8 (Devoxx BE)
Code Review Matters and Manners
Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (Devoxx UK)
Staying Ahead of the Curve
Level Up Your Automated Tests

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Reach Out and Touch Someone: Haptics and Empathic Computing
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Per capita expenditure prediction using model stacking based on satellite ima...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...

Concurrent Programming Using the Disruptor

Editor's Notes

  • #2: Caveats\n - Not much code - will be available\n
  • #3: Who has heard of it?\nWho has seen other presentations or read blogs?\nWho has played with it?\n Open Source\n Message Passing\n
  • #4: What it does, and how it works\nThe really cool stuff\n
  • #5: Uncontended data structure * except multiple producers\nWay to pass data between threads very fast\n\n
  • #6: That&amp;#x2019;s just words\n
  • #7: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #8: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #9: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #10: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #11: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #12: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #13: It is not, in fact, magic\nArray-backed ring buffer\nSequence numbers\nNothing magic\n not going to touch on: how the ring buffer doesn&amp;#x2019;t wrap; \n
  • #14: Generics to type it\n
  • #15: Garbage friendly\nReuse the events\n
  • #16: Garbage friendly - event factory\n\n
  • #17: \n
  • #18: Producer, writer...\nBlack &amp; White classes are provided by the Disruptor\nColoured ones are your own\n
  • #19: \n
  • #20: \n
  • #21: \n
  • #22: \n
  • #23: \n
  • #24: \n
  • #25: \n
  • #26: \n
  • #27: Disruptor provides a BatchEventProcessor \nfor heavy lifting\n
  • #28: Again, coloured classes for you\n
  • #29: \n
  • #30: \n
  • #31: \n
  • #32: \n
  • #33: \n
  • #34: \n
  • #35: \n
  • #36: \n
  • #37: \n
  • #38: \n
  • #39: \n
  • #40: \n
  • #41: \n
  • #42: \n
  • #43: Fast, uncontended replacement for a queue\nvery garbage friendly (or can be)\n
  • #44: Uncontended means things can really work in parallel\n\nHas anyone seen this before?\n
  • #45: \n
  • #46: Imagine the world&amp;#x2019;s most rubbish car\n
  • #47: \n
  • #48: \n
  • #49: \n
  • #50: \n
  • #51: \n
  • #52: \n
  • #53: Tada!\n
  • #54: \n
  • #55: \n
  • #56: \n
  • #57: \n
  • #58: \n
  • #59: Sequence barriers\n
  • #60: \n
  • #61: \n
  • #62: \n
  • #63: \n
  • #64: \n
  • #65: \n
  • #66: \n
  • #67: \n
  • #68: \n
  • #69: \n
  • #70: Maybe putting engine in takes a while\nMaybe it needs to go to a database to get the &amp;#x201C;engine&amp;#x201D;\nPassenger seat might be retrieved from another webservice\n\n
  • #71: \n
  • #72: Dude can put engines in more than one car\nDude will write engines into different cars in the ring buffer\nThis is the only thing that can write this field\n
  • #73: Maybe the seats are retrieved from another service\n
  • #74: \n
  • #75: 3 cars\n
  • #76: 2 cars\n
  • #77: 4 cars\n
  • #78: \n
  • #79: Bonnet is dead fast. Maybe it&amp;#x2019;s calculating the result based on what&amp;#x2019;s already in the ringbuffer\n\n
  • #80: Bonnet handler writes results into 33\n
  • #81: Front door handler is sloooow. Maybe it got caught waiting for something else, or it&amp;#x2019;s sub-optimal\nAll door handlers ask their sequence barrier for the next available sequence\nthis is the lowest of the sequence numbers that barrier is tracking\nin that case, it&amp;#x2019;s 35 - rear seat handler\n
  • #82: In this case its 35\n
  • #83: front door handler is waaaaay behind\nhe&amp;#x2019;s going to have to put his door into a bunch of cars\n
  • #84: \n
  • #85: \n
  • #86: \n
  • #87: \n
  • #88: Not going to show writing to the buffer\n
  • #89: Wheels blocked because they&amp;#x2019;re already at 27\nRingBuffer is blocked cos it can&amp;#x2019;t write any more\nBack-pressure\n
  • #90: \n
  • #91: \n
  • #92: \n
  • #93: \n
  • #94: Can&amp;#x2019;t run the car demo at full speed on a machine with two cores\nFields have to be volatile\nStill low contention, but you are contending upon CPU\nYour ring buffer should be bigger than 12\n
  • #95: \n
  • #96: Martin Fowler talks about DDD this morning. Aggregates.\nTake care of separate concerns in separate processes\nSharding\nJoe Armstrong spoke about handling errors outside of your process. Can have processes outside of your business logic\n\n\n
  • #97: \n
  • #98: Feedback - any interest in a workshop?\nWhat else do you want to know about?\n.net version\n