SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
Dan McKinley
 

Mais procurados (20)

Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
Disruptor
DisruptorDisruptor
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
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
Distributed Lock Manager
Distributed Lock ManagerDistributed Lock Manager
Distributed Lock Manager
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
My First 90 days with Vitess
My First 90 days with VitessMy First 90 days with Vitess
My First 90 days with Vitess
 
MySQL Monitoring using Prometheus & Grafana
MySQL Monitoring using Prometheus & GrafanaMySQL Monitoring using Prometheus & Grafana
MySQL Monitoring using Prometheus & Grafana
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
From distributed caches to in-memory data grids
From distributed caches to in-memory data gridsFrom distributed caches to in-memory data grids
From distributed caches to in-memory data grids
 
Key-Value NoSQL Database
Key-Value NoSQL DatabaseKey-Value NoSQL Database
Key-Value NoSQL Database
 
Cassandra at Instagram 2016 (Dikang Gu, Facebook) | Cassandra Summit 2016
Cassandra at Instagram 2016 (Dikang Gu, Facebook) | Cassandra Summit 2016Cassandra at Instagram 2016 (Dikang Gu, Facebook) | Cassandra Summit 2016
Cassandra at Instagram 2016 (Dikang Gu, Facebook) | Cassandra Summit 2016
 
Pinot: Near Realtime Analytics @ Uber
Pinot: Near Realtime Analytics @ UberPinot: Near Realtime Analytics @ Uber
Pinot: Near Realtime Analytics @ Uber
 
Implementing Domain Events with Kafka
Implementing Domain Events with KafkaImplementing Domain Events with Kafka
Implementing Domain Events with Kafka
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
 

Destaque

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
 

Destaque (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
 
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
 
Device Simulator with Akka
Device Simulator with AkkaDevice Simulator with Akka
Device Simulator with Akka
 

Semelhante a 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
 

Semelhante a 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
 

Mais de Stephan Schmidt

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

Mais de 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
 

Último

Último (20)

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
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
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...
 
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...
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 

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