SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Die LMAX-Architecture with
Disruptors:

6M Transactions per Second




Stephan Schmidt, Vice CTO, brands4friends
Me
Stephan Schmidt
Vice CTO brands4friends




@codemonkeyism
www.codemonkeyism.com

stephan.schmidt@brands4friends.de
3
brands4friends
    No.1 Shopping Club in Germany
    > 360k daily visitors
    > 4.5M Users
    eBay company


5   20.04.12   WJAX 2011
6
7
Development at
brands4friends

Team
Java and web developers,
data warehouse developers

Process
Scrum since 2009
Kanban for DWH since
2012
LMAX - The London Multi-Asset Exchange




     "We aim to build the highest
     performance financial exchange in
     the world"




9   20.04.12   Fußzeilentext
High Performance Transaction Processing




10   20.04.12   Fußzeilentext
Business
   Receive          Unmarshal     Journal   Replicate              Marshall   Send
                                                         Logic

Service / Transaction Processor
Business
   Receive              Unmarshal           Journal           Replicate                              Marshall           Send
                                                                                   Logic
                Queue




                                    Queue




                                                      Queue




                                                                          Queue




                                                                                             Queue




                                                                                                                Queue
Service / Transaction Processor
Cores




    Ghz CPU
Actors?
                         SEDA?


14   20.04.12   Fußzeilentext
Stuff that did not work for various reasons


     1.  RDBMS
     2.  Actors                    Receive              Unmarshal           Journal           Replicate
                                                                                                                  Business
                                                                                                                   Logic
                                                                                                                                     Marshall           Send




                                                Queue




                                                                    Queue




                                                                                      Queue




                                                                                                          Queue




                                                                                                                             Queue




                                                                                                                                                Queue
     3.  SEDA                   Service / Transaction Processor




     4.  J2EE
         …




15   20.04.12   Fußzeilentext
LMAX Architecture




16   20.04.12   Fußzeilentext
Business
   Receive              Unmarshal           Journal           Replicate                              Marshall           Send
                                                                                   Logic
                Queue




                                    Queue




                                                      Queue




                                                                          Queue




                                                                                             Queue




                                                                                                                Queue
Service / Transaction Processor
Size
Linked List Queue


           Node         Node   Node           Node
Add                                                        Remove




                                      Add
                                                         Remove

 Array Queue




               Cache Line                   Cache Line
Queue as a data structure
     Problems with Queues

     1.  Reading (Take) and Writing (Add) are both write access
          => Write Contention
     2.  Write Contention solves with Locks
         1.  Other solutions include Deques
     3.  Locks lead to context switches to the kernel
         1.  Context switches lead to CPU cache misses etc.
       2.  Kernel might use opportunity to do other stuff as well




19
Locks
     Costs according to LMAX Paper



             Method                     Time in ms
             Single Thread              300
             Single Thread mit Lock     10.000
             Zwei Threads mit Lock      224.000
             Single Thread mit CAS      5.700
             Zwei Threads mit CAS       30.000
             Single Thread/             4.700
             Volatile Write

     “Compare And Swap”
     Atomic Reference etc. in Java =>
     No Context Switch                            Memory Read/Write Barrier

20
LMAX Data Structure – Ring Buffer




                                           Event
     Publisher
                                         Processor




                  Ring Buffer




21
Pre-Allocation of Buckets




                                                    31 30 29 28
                                               0                      27
                                          1                                26
                                      2                                      25
                                  3                                               24
                              4                                                      23
                              5                                                       22     Event
     Publisher
                             6                                                        21   Processor
                              7                                                       20
                                  8                                                  19
                                      9                                         18
                                          10                               17
                                               11                     16
                                                    12           15
                                                         13 14

                        Ring Buffer

2^5
            •  No (less) GC problems
            •  Objects are near each other in memory
22
               => cache friendly
Coordination




                                                31 30 29 28
                                           0                      27
                                      1                                26
                                  2                                      25
                              3                                               24
                          4                                                      23
                         5                                                        22       Event
     Publisher
                         6                                                        21     Processor
                          7                                                       20
 Claim                        8                                                  19    Wait
 Strategy                         9                                         18         Strategy
                                      10                               17
                                           11                     16
                                                12           15
                                                     13 14

                    Ring Buffer

2^5
                 1.Claim
                 2.Write
                 3.Make Public by advancing sequence
23
Latency

                                                                                  Business
   Receive              Unmarshal           Journal           Replicate                              Marshall           Send
                                                                                   Logic
                Queue




                                    Queue




                                                      Queue




                                                                          Queue




                                                                                             Queue




                                                                                                                Queue
Service / Transaction Processor
Journal




Receive   Replicate    Business
Message                 Logic


          Unmarshall
Business
   Receive          Unmarshal              Journal   Replicate              Marshall          Send
                                                                  Logic




                                  Datenstruktur




                                                                              Datenstruktur
Service / Transaction Processor
LMAX Architektur




  Input Disruptor                            Ouput Disruptor
                                              Ouput Disruptor
                                               Ouput Disruptor
                    Business Logic Handler
HA Node

                                                                          Publisher
                 Receiver

                            Replicator



                                                             Marshaller

                            Journaler




                              Un-
                            Marshaller
                                                                                      Output Disruptor
          Input Disruptor                   File System



Jede Stage
kann mehrere                        Business Logic Handler

Threads haben


28
Receiver writes on 31.
                                        Journaler and Replicator read
                                        on 24 and can move up the
            Receiver                    sequence to 30.


                                          Journaler




               31                                     Replicator



                               24


                                                                        Un-Marshaller can move beyond
                                                        Un-             Journaler and Replicator up to
                                                      Marshaller        30.

                                   19
                              18



                                                                   Business Logic Handler needs
                               Business Logic                      to stay behind all others.
                                  Handler


29
Java API




30   20.04.12   Fußzeilentext
C1


P1
     C2


     C3


     C4
C2


P1   C1   C3


          C4
C1   C2



P1


     C3   C4
C2



P1   C1        C4


          C3
P1


     C1



P2
Demo



38   20.04.12   Fußzeilentext
LMAX Low Level Ideas


     1.  Simple Code
     2.  Everything in memory
     3.  Single threaded per CPU for business logic
     4.  Business logic has no I/O, I/O is done somewhere else
     5.  Scheduler “knows” dependencies of handlers




39   20.04.12   Fußzeilentext
6M TPS? How did LMAX do it?
                                                                x 10


                                    x 10

     3 billions of                                                     1000K+ TPS
     instructions
     on modern                                                         Custom, cache friendly
     CPU                                                               collections
                                           100K+ TPS
                                                                       Performance Testing
                                           Clean organized code
                                                                       Controlled GC
                                           Standard libraries
               10K+ TPS                                                Very well modeled
                                                                       domain
               If you don't do anything
               stupid




40
We’re looking for very good developers
Thanks!
@codemonkeyism
stephan.schmidt@brands4friends.de
Images CC from Flickr:
     nimboo, imjustcreative,
     gremionis, justonlysteve,
     John_Scone, Matthias
     Wicke, irisgodd3ss,
     TunnelBug, alandd,
     seasonal wanderer,
     raulbarraltamayo, Gilmoth,
     Dunechaser, graftedno1


43
Sources


     “Disruptor: High performance alternative to bounded queues for exchanging
        data between concurrent threads”, Martin Thompson, Dave Farley,
        Michael Barker, Patricia Gee, Andrew Stewart, 2011


     "The LMAX Architecture”, Martin Fowler, 2011
     http://martinfowler.com/articles/lmax.html


     “How to do 100K+ TPS at less than 1ms latency”, Martin Thompson, Michael
        Barker, 2010




44   20.04.12   Fußzeilentext

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
Derek Stainer
 
Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE
Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE
Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE
confluent
 

Was ist angesagt? (20)

Kafka 101
Kafka 101Kafka 101
Kafka 101
 
Concurrent Programming Using the Disruptor
Concurrent Programming Using the DisruptorConcurrent Programming Using the Disruptor
Concurrent Programming Using the Disruptor
 
Building an Event Bus at Scale
Building an Event Bus at ScaleBuilding an Event Bus at Scale
Building an Event Bus at Scale
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Apache Kafka - Martin Podval
Apache Kafka - Martin PodvalApache Kafka - Martin Podval
Apache Kafka - Martin Podval
 
Pub/Sub Messaging
Pub/Sub MessagingPub/Sub Messaging
Pub/Sub Messaging
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
Event Driven-Architecture from a Scalability perspective
Event Driven-Architecture from a Scalability perspectiveEvent Driven-Architecture from a Scalability perspective
Event Driven-Architecture from a Scalability perspective
 
From Three Nines to Five Nines - A Kafka Journey
From Three Nines to Five Nines - A Kafka JourneyFrom Three Nines to Five Nines - A Kafka Journey
From Three Nines to Five Nines - A Kafka Journey
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introduction
 
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and PinotExactly-Once Financial Data Processing at Scale with Flink and Pinot
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
 
Kafka PPT.pptx
Kafka PPT.pptxKafka PPT.pptx
Kafka PPT.pptx
 
Blockchain Presentation
Blockchain PresentationBlockchain Presentation
Blockchain Presentation
 
Unique ID generation in distributed systems
Unique ID generation in distributed systemsUnique ID generation in distributed systems
Unique ID generation in distributed systems
 
Kafka: All an engineer needs to know
Kafka: All an engineer needs to knowKafka: All an engineer needs to know
Kafka: All an engineer needs to know
 
Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE
Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE
Kafka Multi-Tenancy—160 Billion Daily Messages on One Shared Cluster at LINE
 
Rate limiting
Rate limitingRate limiting
Rate limiting
 

Andere mochten auch

Beginners guide-concurrency
Beginners guide-concurrencyBeginners guide-concurrency
Beginners guide-concurrency
Michael Barker
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
MongoDB
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based Applications
NLJUG
 

Andere mochten auch (20)

Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
 
Workshop: Introduction to the Disruptor
Workshop: Introduction to the DisruptorWorkshop: Introduction to the Disruptor
Workshop: Introduction to the Disruptor
 
LMAX Disruptor - High Performance Inter-Thread Messaging Library
LMAX Disruptor - High Performance Inter-Thread Messaging LibraryLMAX Disruptor - High Performance Inter-Thread Messaging Library
LMAX Disruptor - High Performance Inter-Thread Messaging Library
 
Employee Live Cycle JAX 2016
Employee Live Cycle JAX 2016Employee Live Cycle JAX 2016
Employee Live Cycle JAX 2016
 
Short Guide to Productivity
Short Guide to ProductivityShort Guide to Productivity
Short Guide to Productivity
 
Beginners guide-concurrency
Beginners guide-concurrencyBeginners guide-concurrency
Beginners guide-concurrency
 
What Top Management Needs to Know About IT
What Top Management Needs to Know About ITWhat Top Management Needs to Know About IT
What Top Management Needs to Know About IT
 
Akka - Developing SEDA Based Applications
Akka - Developing SEDA Based ApplicationsAkka - Developing SEDA Based Applications
Akka - Developing SEDA Based Applications
 
Value Types
Value TypesValue Types
Value Types
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
 
Infinispan, a distributed in-memory key/value data grid and cache
 Infinispan, a distributed in-memory key/value data grid and cache Infinispan, a distributed in-memory key/value data grid and cache
Infinispan, a distributed in-memory key/value data grid and cache
 
DDD Basics - Context mapping
DDD Basics - Context mappingDDD Basics - Context mapping
DDD Basics - Context mapping
 
Introduction to the Actor Model
Introduction to the Actor ModelIntroduction to the Actor Model
Introduction to the Actor Model
 
BFF Pattern in Action: SoundCloud’s Microservices
BFF Pattern in Action: SoundCloud’s MicroservicesBFF Pattern in Action: SoundCloud’s Microservices
BFF Pattern in Action: SoundCloud’s Microservices
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
IPT High Performance Reactive Programming with JAVA 8 and JavaScript
IPT High Performance Reactive Programming with JAVA 8 and JavaScriptIPT High Performance Reactive Programming with JAVA 8 and JavaScript
IPT High Performance Reactive Programming with JAVA 8 and JavaScript
 
SAS University Edition - Getting Started
SAS University Edition - Getting StartedSAS University Edition - Getting Started
SAS University Edition - Getting Started
 
Процесс проектирования ИТ-решений
Процесс проектирования ИТ-решенийПроцесс проектирования ИТ-решений
Процесс проектирования ИТ-решений
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based Applications
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
 

Ähnlich wie LMAX Architecture

Game cloud reference architecture
Game cloud reference architectureGame cloud reference architecture
Game cloud reference architecture
Jonathan Spindel
 
Building an elastic real time no sql platform
Building an elastic real time no sql platform Building an elastic real time no sql platform
Building an elastic real time no sql platform
dfilppi
 
Supercharging Cassandra - GOTO Amsterdam
Supercharging Cassandra - GOTO AmsterdamSupercharging Cassandra - GOTO Amsterdam
Supercharging Cassandra - GOTO Amsterdam
Acunu
 
[F6]sooin lang vlab
[F6]sooin lang vlab[F6]sooin lang vlab
[F6]sooin lang vlab
NAVER D2
 
Florian adler minute project
Florian adler   minute projectFlorian adler   minute project
Florian adler minute project
Dmitry Buzdin
 
Pattern: an open source project for migrating predictive models onto Apache H...
Pattern: an open source project for migrating predictive models onto Apache H...Pattern: an open source project for migrating predictive models onto Apache H...
Pattern: an open source project for migrating predictive models onto Apache H...
Paco Nathan
 
Web standards, why care?
Web standards, why care?Web standards, why care?
Web standards, why care?
Thomas Roessler
 
A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...
A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...
A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...
ricky_pi_tercios
 

Ähnlich wie LMAX Architecture (20)

Game cloud reference architecture
Game cloud reference architectureGame cloud reference architecture
Game cloud reference architecture
 
Usenix lisa 2011
Usenix lisa 2011Usenix lisa 2011
Usenix lisa 2011
 
Semantic Web Services Framework for Computational Interoperability
Semantic Web Services Framework for Computational InteroperabilitySemantic Web Services Framework for Computational Interoperability
Semantic Web Services Framework for Computational Interoperability
 
Building an elastic real time no sql platform
Building an elastic real time no sql platform Building an elastic real time no sql platform
Building an elastic real time no sql platform
 
Supercharging Cassandra - GOTO Amsterdam
Supercharging Cassandra - GOTO AmsterdamSupercharging Cassandra - GOTO Amsterdam
Supercharging Cassandra - GOTO Amsterdam
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
 
[F6]sooin lang vlab
[F6]sooin lang vlab[F6]sooin lang vlab
[F6]sooin lang vlab
 
Florian adler minute project
Florian adler   minute projectFlorian adler   minute project
Florian adler minute project
 
Balancing Replication and Partitioning in a Distributed Java Database
Balancing Replication and Partitioning in a Distributed Java DatabaseBalancing Replication and Partitioning in a Distributed Java Database
Balancing Replication and Partitioning in a Distributed Java Database
 
Pattern: an open source project for migrating predictive models onto Apache H...
Pattern: an open source project for migrating predictive models onto Apache H...Pattern: an open source project for migrating predictive models onto Apache H...
Pattern: an open source project for migrating predictive models onto Apache H...
 
No Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time JavaNo Heap Remote Objects for Distributed real-time Java
No Heap Remote Objects for Distributed real-time Java
 
Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012
 
Valtech Days 2009 Paris Presentation: WCM in 2010 and an intro to CQ5
Valtech Days 2009 Paris Presentation: WCM in 2010 and an intro to CQ5Valtech Days 2009 Paris Presentation: WCM in 2010 and an intro to CQ5
Valtech Days 2009 Paris Presentation: WCM in 2010 and an intro to CQ5
 
Cascading meetup #4 @ BlueKai
Cascading meetup #4 @ BlueKaiCascading meetup #4 @ BlueKai
Cascading meetup #4 @ BlueKai
 
DAC 2012
DAC 2012DAC 2012
DAC 2012
 
Jazoon 2011 - Smart EAI with Apache Camel
Jazoon 2011 - Smart EAI with Apache CamelJazoon 2011 - Smart EAI with Apache Camel
Jazoon 2011 - Smart EAI with Apache Camel
 
Web standards, why care?
Web standards, why care?Web standards, why care?
Web standards, why care?
 
A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...
A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...
A Methodology for the Emulation of Boolean Logic that Paved the Way for the S...
 
Ese2008 Swordfish
Ese2008 SwordfishEse2008 Swordfish
Ese2008 Swordfish
 
Seattle Scalability - GigaSpaces / Cassandra
Seattle Scalability - GigaSpaces / CassandraSeattle Scalability - GigaSpaces / Cassandra
Seattle Scalability - GigaSpaces / Cassandra
 

Mehr von Stephan Schmidt

What managers need_to_know
What managers need_to_knowWhat managers need_to_know
What managers need_to_know
Stephan Schmidt
 

Mehr von Stephan Schmidt (8)

Focus, Focus, Focus - The one thing that makes a difference
Focus, Focus, Focus - The one thing that makes a differenceFocus, Focus, Focus - The one thing that makes a difference
Focus, Focus, Focus - The one thing that makes a difference
 
State Models for React with Redux
State Models for React with ReduxState Models for React with Redux
State Models for React with Redux
 
10 Years of My Scrum Experience
10 Years of My Scrum Experience10 Years of My Scrum Experience
10 Years of My Scrum Experience
 
What managers need_to_know
What managers need_to_knowWhat managers need_to_know
What managers need_to_know
 
What everyone should know about time to market
What everyone should know about time to marketWhat everyone should know about time to market
What everyone should know about time to market
 
Developer Testing
Developer TestingDeveloper Testing
Developer Testing
 
Better Strategies for Null Handling in Java
Better Strategies for Null Handling in JavaBetter Strategies for Null Handling in Java
Better Strategies for Null Handling in Java
 
Berlin.JAR: Web future without web frameworks
Berlin.JAR: Web future without web frameworksBerlin.JAR: Web future without web frameworks
Berlin.JAR: Web future without web frameworks
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

LMAX Architecture

  • 1. Die LMAX-Architecture with Disruptors: 6M Transactions per Second Stephan Schmidt, Vice CTO, brands4friends
  • 2. Me Stephan Schmidt Vice CTO brands4friends @codemonkeyism www.codemonkeyism.com stephan.schmidt@brands4friends.de
  • 3. 3
  • 4.
  • 5. brands4friends No.1 Shopping Club in Germany > 360k daily visitors > 4.5M Users eBay company 5 20.04.12 WJAX 2011
  • 6. 6
  • 7. 7
  • 8. Development at brands4friends Team Java and web developers, data warehouse developers Process Scrum since 2009 Kanban for DWH since 2012
  • 9. LMAX - The London Multi-Asset Exchange "We aim to build the highest performance financial exchange in the world" 9 20.04.12 Fußzeilentext
  • 10. High Performance Transaction Processing 10 20.04.12 Fußzeilentext
  • 11. Business Receive Unmarshal Journal Replicate Marshall Send Logic Service / Transaction Processor
  • 12. Business Receive Unmarshal Journal Replicate Marshall Send Logic Queue Queue Queue Queue Queue Queue Service / Transaction Processor
  • 13. Cores Ghz CPU
  • 14. Actors? SEDA? 14 20.04.12 Fußzeilentext
  • 15. Stuff that did not work for various reasons 1.  RDBMS 2.  Actors Receive Unmarshal Journal Replicate Business Logic Marshall Send Queue Queue Queue Queue Queue Queue 3.  SEDA Service / Transaction Processor 4.  J2EE … 15 20.04.12 Fußzeilentext
  • 16. LMAX Architecture 16 20.04.12 Fußzeilentext
  • 17. Business Receive Unmarshal Journal Replicate Marshall Send Logic Queue Queue Queue Queue Queue Queue Service / Transaction Processor
  • 18. Size Linked List Queue Node Node Node Node Add Remove Add Remove Array Queue Cache Line Cache Line
  • 19. Queue as a data structure Problems with Queues 1.  Reading (Take) and Writing (Add) are both write access => Write Contention 2.  Write Contention solves with Locks 1.  Other solutions include Deques 3.  Locks lead to context switches to the kernel 1.  Context switches lead to CPU cache misses etc. 2.  Kernel might use opportunity to do other stuff as well 19
  • 20. Locks Costs according to LMAX Paper Method Time in ms Single Thread 300 Single Thread mit Lock 10.000 Zwei Threads mit Lock 224.000 Single Thread mit CAS 5.700 Zwei Threads mit CAS 30.000 Single Thread/ 4.700 Volatile Write “Compare And Swap” Atomic Reference etc. in Java => No Context Switch Memory Read/Write Barrier 20
  • 21. LMAX Data Structure – Ring Buffer Event Publisher Processor Ring Buffer 21
  • 22. Pre-Allocation of Buckets 31 30 29 28 0 27 1 26 2 25 3 24 4 23 5 22 Event Publisher 6 21 Processor 7 20 8 19 9 18 10 17 11 16 12 15 13 14 Ring Buffer 2^5 •  No (less) GC problems •  Objects are near each other in memory 22 => cache friendly
  • 23. Coordination 31 30 29 28 0 27 1 26 2 25 3 24 4 23 5 22 Event Publisher 6 21 Processor 7 20 Claim 8 19 Wait Strategy 9 18 Strategy 10 17 11 16 12 15 13 14 Ring Buffer 2^5 1.Claim 2.Write 3.Make Public by advancing sequence 23
  • 24. Latency Business Receive Unmarshal Journal Replicate Marshall Send Logic Queue Queue Queue Queue Queue Queue Service / Transaction Processor
  • 25. Journal Receive Replicate Business Message Logic Unmarshall
  • 26. Business Receive Unmarshal Journal Replicate Marshall Send Logic Datenstruktur Datenstruktur Service / Transaction Processor
  • 27. LMAX Architektur Input Disruptor Ouput Disruptor Ouput Disruptor Ouput Disruptor Business Logic Handler
  • 28. HA Node Publisher Receiver Replicator Marshaller Journaler Un- Marshaller Output Disruptor Input Disruptor File System Jede Stage kann mehrere Business Logic Handler Threads haben 28
  • 29. Receiver writes on 31. Journaler and Replicator read on 24 and can move up the Receiver sequence to 30. Journaler 31 Replicator 24 Un-Marshaller can move beyond Un- Journaler and Replicator up to Marshaller 30. 19 18 Business Logic Handler needs Business Logic to stay behind all others. Handler 29
  • 30. Java API 30 20.04.12 Fußzeilentext
  • 31.
  • 32.
  • 33. C1 P1 C2 C3 C4
  • 34. C2 P1 C1 C3 C4
  • 35. C1 C2 P1 C3 C4
  • 36. C2 P1 C1 C4 C3
  • 37. P1 C1 P2
  • 38. Demo 38 20.04.12 Fußzeilentext
  • 39. LMAX Low Level Ideas 1.  Simple Code 2.  Everything in memory 3.  Single threaded per CPU for business logic 4.  Business logic has no I/O, I/O is done somewhere else 5.  Scheduler “knows” dependencies of handlers 39 20.04.12 Fußzeilentext
  • 40. 6M TPS? How did LMAX do it? x 10 x 10 3 billions of 1000K+ TPS instructions on modern Custom, cache friendly CPU collections 100K+ TPS Performance Testing Clean organized code Controlled GC Standard libraries 10K+ TPS Very well modeled domain If you don't do anything stupid 40
  • 41. We’re looking for very good developers
  • 43. Images CC from Flickr: nimboo, imjustcreative, gremionis, justonlysteve, John_Scone, Matthias Wicke, irisgodd3ss, TunnelBug, alandd, seasonal wanderer, raulbarraltamayo, Gilmoth, Dunechaser, graftedno1 43
  • 44. Sources “Disruptor: High performance alternative to bounded queues for exchanging data between concurrent threads”, Martin Thompson, Dave Farley, Michael Barker, Patricia Gee, Andrew Stewart, 2011 "The LMAX Architecture”, Martin Fowler, 2011 http://martinfowler.com/articles/lmax.html “How to do 100K+ TPS at less than 1ms latency”, Martin Thompson, Michael Barker, 2010 44 20.04.12 Fußzeilentext