SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
Disrup'ng	
  Disruptor	
  

                  By	
  	
  
         Azrul	
  MADISA	
  
(azrul.madisa@my.experian.com)	
  
About	
  me	
  
•  Call	
  me	
  Azrul	
  
•  Solu'on	
  Architect	
  at	
  Experian	
  Decision	
  
   Analy'cs	
  
•  In	
  charge	
  of	
  Experian’s	
  stuff:	
  
    –  BI	
  
    –  Business	
  Ac'vity	
  Monitoring	
  
    –  Integra'on	
  
          •  OSGi	
  stuff	
  
•  Love	
  to	
  read	
  
•  Black	
  belt	
  in	
  Aikido	
  
•  No	
  concurrency	
  expert,	
  
    –  	
  just	
  a	
  wild	
  enthusiast!!	
  
Menu	
  of	
  the	
  day	
  
•      Why	
  concurrency?	
  
•      Concurrency	
  is	
  hard	
  
•      Producer	
  consumer	
  
•      Using	
  disruptor	
  
•      PaUerns	
  
	
  
Why	
  concurrency?	
  
•    Cloud	
  
•    Mul'-­‐core	
  
•    Mul'-­‐channel	
  
•    Complex	
  business	
  
     process	
  
Concurrency	
  is	
  hard!	
  
Wait	
  for	
  resource	
  A	
  
 to	
  be	
  available	
  


Reserve	
  resource	
  A	
  


Wait	
  for	
  resource	
  B	
  
 to	
  be	
  available	
  


Reserve	
  resource	
  B	
  


      Use	
  A	
  and	
  B	
  


  Release	
  A	
  and	
  B	
  
Concurrency	
  is	
  hard!	
  
Wait	
  for	
  resource	
  A	
              Wait	
  for	
  resource	
  B	
  
 to	
  be	
  available	
                     to	
  be	
  available	
  


Reserve	
  resource	
  A	
                  Reserve	
  resource	
  B	
  


Wait	
  for	
  resource	
  B	
              Wait	
  for	
  resource	
  A	
  
 to	
  be	
  available	
                     to	
  be	
  available	
  


Reserve	
  resource	
  B	
                  Reserve	
  resource	
  A	
  


      Use	
  A	
  and	
  B	
                      Use	
  A	
  and	
  B	
  


  Release	
  A	
  and	
  B	
                  Release	
  A	
  and	
  B	
  
Concurrency	
  is	
  hard!	
  
Wait	
  for	
  resource	
  A	
                          Wait	
  for	
  resource	
  B	
  
 to	
  be	
  available	
                                 to	
  be	
  available	
  


Reserve	
  resource	
  A	
                              Reserve	
  resource	
  B	
  


Wait	
  for	
  resource	
  B	
     Stuck	
  here!	
     Wait	
  for	
  resource	
  A	
  
 to	
  be	
  available	
                                 to	
  be	
  available	
  


Reserve	
  resource	
  B	
                              Reserve	
  resource	
  A	
  


      Use	
  A	
  and	
  B	
                                  Use	
  A	
  and	
  B	
  


  Release	
  A	
  and	
  B	
                              Release	
  A	
  and	
  B	
  
Concurrency	
  is	
  hard!	
  
•  Random	
  decisions	
  in	
  different	
  places	
  influence	
  
   each	
  other	
  
•  Influence	
  each	
  other	
  BADLY!	
  
Solving	
  concurrency	
  with	
  locking	
  
Wait	
  for	
  resource	
  A	
                   Wait	
  for	
  resource	
  B	
  
 to	
  be	
  available	
                          to	
  be	
  available	
  


Reserve	
  resource	
  A	
                       Reserve	
  resource	
  B	
  
                                   Monitor	
  
Wait	
  for	
  resource	
  B	
                   Wait	
  for	
  resource	
  A	
  
 to	
  be	
  available	
                          to	
  be	
  available	
  


 Reserve	
  resource	
  B	
                      Reserve	
  resource	
  A	
  


      Use	
  A	
  and	
  B	
                           Use	
  A	
  and	
  B	
  


   Release	
  A	
  and	
  B	
                      Release	
  A	
  and	
  B	
  
Solving	
  concurrency	
  with	
  locking	
  
•  Locking	
  is	
  done	
  through	
  
   ‘monitors’	
  
•  OS	
  or	
  VM	
  level	
  
•  Like	
  a	
  toilet	
  
    –  If	
  someone	
  is	
  using	
  it,	
  everyone	
  
       else	
  has	
  to	
  wait	
  
    –  Acquiring	
  a	
  lock	
  is	
  generally	
  
       SLOW!	
  
CAS	
  to	
  the	
  rescue	
  
•    CAS	
  =	
  Compare-­‐And-­‐Swap	
  
•    ‘Hardware’	
  level	
  locking	
  
•    Atomic	
  opera'ons	
  
•    Crazy	
  fast	
  –	
  mul'-­‐core	
  friendly	
  
CAS	
  to	
  the	
  rescue	
  –	
  incremen'ng	
  a	
  
                                value	
           Shared	
  memory	
  
                        Get	
  ‘input’	
     Input	
  =	
  21	
  
                                                                                             21	
  
Changed	
  by	
  
 another	
              Increment	
  
                                             Input	
  =	
  21	
      result	
  =	
  22	
  
  thread	
                   	
  

                         Compare	
  
                                             Input	
  =	
  21	
  
         Different	
         	
  




                                  Same	
  

                             Set	
  
                                             result	
  =	
  22	
  
                              	
  
CAS	
  to	
  the	
  rescue	
  
•  Java	
  example	
  

	
  AtomicInteger	
  counter	
  =	
  new	
  AtomicInteger(1);	
  
	
  …	
  
	
  int	
  currentValue	
  =	
  counter.getAndIncrement();	
  
PRODUCER	
  -­‐	
  CONSUMER	
  
Producer	
  -­‐	
  consumer	
  
Producers	
  	
  
Producer	
  -­‐	
  consumer	
  
Producers	
  	
  




                                  Mess	
  
Producer	
  -­‐	
  consumer	
  
Producers	
  	
                              Consumer	
  (cleaner)	
  




                                  Mess	
  
Producer	
  -­‐	
  consumer	
  
•  Other	
  examples	
  
   	
     Industry	
          Producer	
            Consumer	
  

          Banking	
           Credit	
  card	
      User	
  “credit	
  
                              applica'on	
  	
      worthiness”	
  
                                                    verifica'on	
  


          Insurance	
         Insurance	
           Underwri'ng	
  
                              applica'on	
          process	
  


          Manufacturing	
     Raw	
  material	
     Factory	
  worker	
  
                              delivery	
  
                              	
  
Producer	
  -­‐	
  consumer	
  
•  Problems	
  
   –  Producer	
  is	
  producing	
  faster	
  
      than	
  consumer	
  can	
  
      consumer	
  
Solu'on	
  1:	
  Array	
  blocking	
  queue	
  
•  Classic	
  solu'on:	
  Using	
  array	
  blocking	
  queue	
  
   –  Producer	
  would	
  queue	
  things	
  if	
  consumer	
  is	
  slow	
  
   –  Consumer	
  can	
  consume	
  at	
  its	
  own	
  pace	
  	
  
   –  If	
  queue	
  is	
  full,	
  producer	
  will	
  be	
  blocked	
  
Solu'on	
  1:	
  Array	
  blocking	
  queue	
  
•  Classic	
  solu'on:	
  Using	
  array	
  blocking	
  queue	
  
   –  Advantage:	
  Scalability	
  =	
  many	
  consumers	
  
Solu'on	
  1:	
  Array	
  blocking	
  queue	
  
•  Main	
  problem:	
  
   –  Queue	
  need	
  to	
  be	
  locked	
  
        •  For	
  consumer	
  to	
  read	
  
        •  For	
  producer	
  to	
  write	
  
   –  Producer	
  is	
  blocked	
  if	
  queue	
  is	
  full	
  
   –  Lock	
  =>	
  Slow	
  
Solu'on	
  2:	
  Using	
  ring	
  buffer	
  &	
  CAS	
  




•  Producer	
  will	
  never	
  be	
  blocked	
  –	
  we	
  just	
  “wrap	
  
   around”	
  the	
  circular	
  queue	
  (write	
  over	
  older	
  entry)	
  
•  Elements	
  of	
  ring	
  buffer	
  are	
  set	
  using	
  CAS	
  
•  =>	
  Ring	
  buffer	
  is	
  very	
  very	
  fast	
  
Solu'on	
  2:	
  Using	
  ring	
  buffer	
  &	
  CAS	
  
•  Ring	
  buffer	
  +	
  CAS	
  =	
  Disruptor	
  
•  Create	
  by	
  LMAX	
  
    –  Doing	
  High	
  frequency	
  trading	
  
•  “100	
  k	
  TPS	
  at	
  1	
  ms	
  latency”	
  
•  Disruptor	
  also	
  includes	
  a	
  few	
  
   other	
  op'miza'ons	
  
USING	
  DISRUPTOR	
  
Loan	
  applica'on	
  processing	
  
    Applica'on	
  by	
  user	
  



 Pre-­‐bureau	
  processing	
  


     Call	
  credit	
  bureau	
  
                 	
  


Approved	
  /	
  refer	
  /	
  reject	
  
                	
  


            Save	
  data	
  
                	
  
Loan	
  applica'on	
  processing	
  
    Applica'on	
  by	
  user	
                  Applica'on	
  by	
  user	
  



 Pre-­‐bureau	
  processing	
                Pre-­‐bureau	
  processing	
  


     Call	
  credit	
  bureau	
                  Call	
  credit	
  bureau	
  
                 	
                                          	
  


Approved	
  /	
  refer	
  /	
  reject	
     Approved	
  /	
  refer	
  /	
  reject	
  
                	
                                          	
  


            Save	
  data	
                              Save	
  data	
  
                	
                                          	
  
Loan	
  applica'on	
  processing	
  
    Applica'on	
  by	
  user	
  



 Pre-­‐bureau	
  processing	
  
                                            X	
  100	
  every	
  
     Call	
  credit	
  bureau	
  
                 	
  
                                            second	
  

Approved	
  /	
  refer	
  /	
  reject	
  
                	
  


            Save	
  data	
  
                	
  
Loan	
  applica'on	
  processing	
  

                            Applica'on	
  by	
  user	
  


                          Pre-­‐bureau	
  processing	
  

                              Call	
  credit	
  bureau	
  
                                          	
  




Approved	
  /	
  refer	
  /	
  reject	
                      Save	
  data	
  
                	
                                               	
  
Loan	
  applica'on	
  processing	
  

                            Applica'on	
  by	
  user	
  


                          Pre-­‐bureau	
  processing	
  
                                                                                    Tedious	
  in	
  your	
  
                              Call	
  credit	
  bureau	
                          typical	
  applica'on	
  
                                          	
                                    server	
  (resort	
  to	
  JMS)	
  




Approved	
  /	
  refer	
  /	
  reject	
                      Save	
  data	
  
                	
                                               	
  
Loan	
  applica'on	
  processing	
  –	
  with	
  
               Disruptor	
  
                               Applica'on	
  by	
  user	
  


                                                         Disruptor	
  



                             Pre-­‐bureau	
  processing	
  

                                 Call	
  credit	
  bureau	
  
                                             	
  




   Approved	
  /	
  refer	
  /	
  reject	
                      Save	
  data	
  
                   	
                                               	
  
Loan	
  applica'on	
  processing	
  –	
  with	
  
               Disruptor	
  
                               Applica'on	
  by	
  user	
  


                                                         Disruptor	
  


                                                                                     Handle	
  ‘forking’	
  
                             Pre-­‐bureau	
  processing	
                          Handle	
  parallel	
  users	
  
                                                                                    Handle	
  ‘workflow’	
  
                                 Call	
  credit	
  bureau	
  
                                             	
  




   Approved	
  /	
  refer	
  /	
  reject	
                      Save	
  data	
  
                   	
                                               	
  
Loan	
  applica'on	
  processing	
  –	
  with	
  
                   Disruptor	
  
Disruptor<MyEvent>	
  disruptor	
  =	
  new	
  Disruptor<MyEvent>(…);	
  
	
  
//read	
  data	
  
disruptor.handleEventsWith(preBureauProcessing).	
  //first	
  do	
  this	
  
then(callBureau).	
  //next	
  do	
  this	
  
then(	
  approvedReferReject,	
  saveData);	
  //arer	
  that,	
  do	
  these	
  in	
  parallel	
  
	
  
//run	
  disruptor	
  
RingBuffer<ValueEvent>	
  ringBuffer	
  =	
  disruptor.start();	
  
	
  
//write	
  (applica'on	
  by	
  user)	
  
long	
  sequence	
  =	
  ringBuffer.next();	
  
MyEvent	
  	
  event	
  =	
  ringBuffer.get(sequence);	
  
event.setValue(x);	
  
ringBuffer.publish(sequence);	
  
	
  
Batch	
  reading	
  


Write	
  



Write	
  



Write	
  
Batch	
  reading	
  




             Read	
  
USEFUL	
  PATTERNS	
  
Useful	
  paUerns	
  
•  PaUerns	
  I’ve	
  experimented	
  with	
  
   –  Not	
  ‘in	
  produc'on	
  yet’	
  
   –  Try	
  it	
  out	
  on	
  your	
  own	
  before	
  commisng	
  
   –  	
  Don’t	
  sue	
  me	
  if	
  it	
  blows	
  J	
  
Topic	
  replacement	
  
Topic	
  replacement	
  
         AND	
  
Topic	
  replacement	
  
         AND	
  
Topic	
  replacement	
  
•  Just	
  use	
  disruptor’s	
  ‘default	
  sesng’	
  	
  
Queue	
  replacement	
  
         OR	
  
Queue	
  replacement	
  
•  Use	
  WorkerPool	
  
	
  
WorkerPool<ValueEvent>	
  workerPool	
  =	
  new	
  WorkerPool<ValueEvent>(…);	
  
	
  workerPool.start(…)	
  ;	
  
Actors	
  
•  A	
  unit	
  of	
  concurrent	
  computa'on	
  	
  
•  From	
  wikipedia:	
  
    –  “…	
  in	
  response	
  to	
  a	
  message	
  that	
  it	
  receives,	
  an	
  
       actor	
  can	
  make	
  local	
  decisions,	
  create	
  more	
  
       actors,	
  send	
  more	
  messages,	
  and	
  determine	
  how	
  
       to	
  respond	
  to	
  the	
  next	
  message	
  received”	
  
Actors	
  
Actors	
  
             Actor	
  =	
  Worker	
  Pool	
  (Queue)	
  
Actors	
  
             Actor	
  =	
  Worker	
  Pool	
  (Queue)	
  
Replica'on	
  
‘Topic’	
  layout	
  
Replica'on	
  
        ‘Topic’	
  layout	
  




  JMS	
  


               JMS	
  messaging	
  over	
  network	
  


Listener	
  
Replica'on	
  
        ‘Topic’	
  layout	
  




  JMS	
                                                  Guaranteed	
  delivery	
  


               JMS	
  messaging	
  over	
  network	
  


Listener	
  
Conclusion	
  
•  Disruptor	
  –	
  interes'ng	
  and	
  ‘disrup've’	
  
   framework	
  
•  Revenge	
  of	
  the	
  “object	
  oriented	
  programming”	
  
   model	
  J	
  
•  Do	
  your	
  own	
  experiments	
  
•  Check	
  out:	
  
   –  hUp://code.google.com/p/disruptor/	
  
   –  hUp://mar'nfowler.com/ar'cles/lmax.html	
  
   –  hUp://mechani's.blogspot.com/2011/07/dissec'ng-­‐
      disruptor-­‐wiring-­‐up.html	
  

Contenu connexe

Similaire à Disrupting disruptor

JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...
JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...
JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...InSync2011
 
Robust Cloud Resource Provisioning for Cloud Computing Environments
Robust Cloud Resource Provisioning for Cloud Computing EnvironmentsRobust Cloud Resource Provisioning for Cloud Computing Environments
Robust Cloud Resource Provisioning for Cloud Computing EnvironmentsSivadon Chaisiri
 
Optimization of Resource Provisioning Cost in Cloud Computing
Optimization of Resource Provisioning Cost in Cloud Computing Optimization of Resource Provisioning Cost in Cloud Computing
Optimization of Resource Provisioning Cost in Cloud Computing Sivadon Chaisiri
 
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...Acquia
 
The Straight Skinny on Cloud Platforms
The Straight Skinny on Cloud PlatformsThe Straight Skinny on Cloud Platforms
The Straight Skinny on Cloud PlatformsHostway|HOSTING
 
The Lean Cloud for Startups with AWS - Cost Optimisation
The Lean Cloud for Startups with AWS - Cost OptimisationThe Lean Cloud for Startups with AWS - Cost Optimisation
The Lean Cloud for Startups with AWS - Cost OptimisationAmazon Web Services
 
ConnectWise and eFolder Webinar: From Destruction to Production in 72 Hours
ConnectWise and eFolder Webinar: From Destruction to Production in 72 HoursConnectWise and eFolder Webinar: From Destruction to Production in 72 Hours
ConnectWise and eFolder Webinar: From Destruction to Production in 72 HoursDropbox
 
Cloud conference - mongodb
Cloud conference - mongodbCloud conference - mongodb
Cloud conference - mongodbMitch Pirtle
 
Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...
Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...
Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...Amazon Web Services
 
Applying Boyd's OODA Loop Strategy to Drive IT Security Decision and Action
Applying Boyd's OODA Loop Strategy to Drive IT Security Decision and ActionApplying Boyd's OODA Loop Strategy to Drive IT Security Decision and Action
Applying Boyd's OODA Loop Strategy to Drive IT Security Decision and ActionnCircle - a Tripwire Company
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous DeliveryBrian Kaney
 
Concurrency for dummies
Concurrency for dummiesConcurrency for dummies
Concurrency for dummiesAzrul MADISA
 
SaaS, Multi-Tenancy and Cloud Computing
SaaS, Multi-Tenancy and Cloud ComputingSaaS, Multi-Tenancy and Cloud Computing
SaaS, Multi-Tenancy and Cloud ComputingRainer Stropek
 
Disaster recovery the new imperative
Disaster recovery the new imperativeDisaster recovery the new imperative
Disaster recovery the new imperativeAFCOM
 
Ruby And Rails Amsterdam 2007
Ruby And Rails Amsterdam 2007Ruby And Rails Amsterdam 2007
Ruby And Rails Amsterdam 2007BCC
 
Sql server 2012 ha and dr sql saturday boston
Sql server 2012 ha and dr sql saturday bostonSql server 2012 ha and dr sql saturday boston
Sql server 2012 ha and dr sql saturday bostonJoseph D'Antoni
 
Cost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWS
Cost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWSCost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWS
Cost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWSAmazon Web Services
 
What is Reactive programming?
What is Reactive programming?What is Reactive programming?
What is Reactive programming?Kevin Webber
 
Patterns For Cloud Computing
Patterns For Cloud ComputingPatterns For Cloud Computing
Patterns For Cloud ComputingSimon Guest
 

Similaire à Disrupting disruptor (20)

JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...
JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...
JD Edwards & Peoplesoft 1 _ Dean Hansen _ Achieving cost effective third part...
 
Robust Cloud Resource Provisioning for Cloud Computing Environments
Robust Cloud Resource Provisioning for Cloud Computing EnvironmentsRobust Cloud Resource Provisioning for Cloud Computing Environments
Robust Cloud Resource Provisioning for Cloud Computing Environments
 
Optimization of Resource Provisioning Cost in Cloud Computing
Optimization of Resource Provisioning Cost in Cloud Computing Optimization of Resource Provisioning Cost in Cloud Computing
Optimization of Resource Provisioning Cost in Cloud Computing
 
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
Acquia Managed Cloud: Highly Available Architecture for Highly Unpredictable ...
 
The Straight Skinny on Cloud Platforms
The Straight Skinny on Cloud PlatformsThe Straight Skinny on Cloud Platforms
The Straight Skinny on Cloud Platforms
 
The Lean Cloud for Startups with AWS - Cost Optimisation
The Lean Cloud for Startups with AWS - Cost OptimisationThe Lean Cloud for Startups with AWS - Cost Optimisation
The Lean Cloud for Startups with AWS - Cost Optimisation
 
ConnectWise and eFolder Webinar: From Destruction to Production in 72 Hours
ConnectWise and eFolder Webinar: From Destruction to Production in 72 HoursConnectWise and eFolder Webinar: From Destruction to Production in 72 Hours
ConnectWise and eFolder Webinar: From Destruction to Production in 72 Hours
 
Cloud conference - mongodb
Cloud conference - mongodbCloud conference - mongodb
Cloud conference - mongodb
 
Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...
Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...
Building Cost-Aware Cloud Architectures - Jinesh Varia (AWS) and Adrian Cockc...
 
Applying Boyd's OODA Loop Strategy to Drive IT Security Decision and Action
Applying Boyd's OODA Loop Strategy to Drive IT Security Decision and ActionApplying Boyd's OODA Loop Strategy to Drive IT Security Decision and Action
Applying Boyd's OODA Loop Strategy to Drive IT Security Decision and Action
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Concurrency for dummies
Concurrency for dummiesConcurrency for dummies
Concurrency for dummies
 
SaaS, Multi-Tenancy and Cloud Computing
SaaS, Multi-Tenancy and Cloud ComputingSaaS, Multi-Tenancy and Cloud Computing
SaaS, Multi-Tenancy and Cloud Computing
 
Disaster recovery the new imperative
Disaster recovery the new imperativeDisaster recovery the new imperative
Disaster recovery the new imperative
 
Ruby And Rails Amsterdam 2007
Ruby And Rails Amsterdam 2007Ruby And Rails Amsterdam 2007
Ruby And Rails Amsterdam 2007
 
Cloud Security: Ten Things
Cloud Security: Ten ThingsCloud Security: Ten Things
Cloud Security: Ten Things
 
Sql server 2012 ha and dr sql saturday boston
Sql server 2012 ha and dr sql saturday bostonSql server 2012 ha and dr sql saturday boston
Sql server 2012 ha and dr sql saturday boston
 
Cost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWS
Cost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWSCost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWS
Cost Optimisation in the AWS Cloud, Ianni Vamvadelis, Solutions Architect, AWS
 
What is Reactive programming?
What is Reactive programming?What is Reactive programming?
What is Reactive programming?
 
Patterns For Cloud Computing
Patterns For Cloud ComputingPatterns For Cloud Computing
Patterns For Cloud Computing
 

Dernier

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 interpreternaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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 organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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 Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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 Servicegiselly40
 
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 MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Dernier (20)

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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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 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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Disrupting disruptor

  • 1. Disrup'ng  Disruptor   By     Azrul  MADISA   (azrul.madisa@my.experian.com)  
  • 2. About  me   •  Call  me  Azrul   •  Solu'on  Architect  at  Experian  Decision   Analy'cs   •  In  charge  of  Experian’s  stuff:   –  BI   –  Business  Ac'vity  Monitoring   –  Integra'on   •  OSGi  stuff   •  Love  to  read   •  Black  belt  in  Aikido   •  No  concurrency  expert,   –   just  a  wild  enthusiast!!  
  • 3. Menu  of  the  day   •  Why  concurrency?   •  Concurrency  is  hard   •  Producer  consumer   •  Using  disruptor   •  PaUerns    
  • 4. Why  concurrency?   •  Cloud   •  Mul'-­‐core   •  Mul'-­‐channel   •  Complex  business   process  
  • 5. Concurrency  is  hard!   Wait  for  resource  A   to  be  available   Reserve  resource  A   Wait  for  resource  B   to  be  available   Reserve  resource  B   Use  A  and  B   Release  A  and  B  
  • 6. Concurrency  is  hard!   Wait  for  resource  A   Wait  for  resource  B   to  be  available   to  be  available   Reserve  resource  A   Reserve  resource  B   Wait  for  resource  B   Wait  for  resource  A   to  be  available   to  be  available   Reserve  resource  B   Reserve  resource  A   Use  A  and  B   Use  A  and  B   Release  A  and  B   Release  A  and  B  
  • 7. Concurrency  is  hard!   Wait  for  resource  A   Wait  for  resource  B   to  be  available   to  be  available   Reserve  resource  A   Reserve  resource  B   Wait  for  resource  B   Stuck  here!   Wait  for  resource  A   to  be  available   to  be  available   Reserve  resource  B   Reserve  resource  A   Use  A  and  B   Use  A  and  B   Release  A  and  B   Release  A  and  B  
  • 8. Concurrency  is  hard!   •  Random  decisions  in  different  places  influence   each  other   •  Influence  each  other  BADLY!  
  • 9. Solving  concurrency  with  locking   Wait  for  resource  A   Wait  for  resource  B   to  be  available   to  be  available   Reserve  resource  A   Reserve  resource  B   Monitor   Wait  for  resource  B   Wait  for  resource  A   to  be  available   to  be  available   Reserve  resource  B   Reserve  resource  A   Use  A  and  B   Use  A  and  B   Release  A  and  B   Release  A  and  B  
  • 10. Solving  concurrency  with  locking   •  Locking  is  done  through   ‘monitors’   •  OS  or  VM  level   •  Like  a  toilet   –  If  someone  is  using  it,  everyone   else  has  to  wait   –  Acquiring  a  lock  is  generally   SLOW!  
  • 11. CAS  to  the  rescue   •  CAS  =  Compare-­‐And-­‐Swap   •  ‘Hardware’  level  locking   •  Atomic  opera'ons   •  Crazy  fast  –  mul'-­‐core  friendly  
  • 12. CAS  to  the  rescue  –  incremen'ng  a   value   Shared  memory   Get  ‘input’   Input  =  21   21   Changed  by   another   Increment   Input  =  21   result  =  22   thread     Compare   Input  =  21   Different     Same   Set   result  =  22    
  • 13. CAS  to  the  rescue   •  Java  example    AtomicInteger  counter  =  new  AtomicInteger(1);    …    int  currentValue  =  counter.getAndIncrement();  
  • 15. Producer  -­‐  consumer   Producers    
  • 16. Producer  -­‐  consumer   Producers     Mess  
  • 17. Producer  -­‐  consumer   Producers     Consumer  (cleaner)   Mess  
  • 18. Producer  -­‐  consumer   •  Other  examples     Industry   Producer   Consumer   Banking   Credit  card   User  “credit   applica'on     worthiness”   verifica'on   Insurance   Insurance   Underwri'ng   applica'on   process   Manufacturing   Raw  material   Factory  worker   delivery    
  • 19. Producer  -­‐  consumer   •  Problems   –  Producer  is  producing  faster   than  consumer  can   consumer  
  • 20. Solu'on  1:  Array  blocking  queue   •  Classic  solu'on:  Using  array  blocking  queue   –  Producer  would  queue  things  if  consumer  is  slow   –  Consumer  can  consume  at  its  own  pace     –  If  queue  is  full,  producer  will  be  blocked  
  • 21. Solu'on  1:  Array  blocking  queue   •  Classic  solu'on:  Using  array  blocking  queue   –  Advantage:  Scalability  =  many  consumers  
  • 22. Solu'on  1:  Array  blocking  queue   •  Main  problem:   –  Queue  need  to  be  locked   •  For  consumer  to  read   •  For  producer  to  write   –  Producer  is  blocked  if  queue  is  full   –  Lock  =>  Slow  
  • 23. Solu'on  2:  Using  ring  buffer  &  CAS   •  Producer  will  never  be  blocked  –  we  just  “wrap   around”  the  circular  queue  (write  over  older  entry)   •  Elements  of  ring  buffer  are  set  using  CAS   •  =>  Ring  buffer  is  very  very  fast  
  • 24. Solu'on  2:  Using  ring  buffer  &  CAS   •  Ring  buffer  +  CAS  =  Disruptor   •  Create  by  LMAX   –  Doing  High  frequency  trading   •  “100  k  TPS  at  1  ms  latency”   •  Disruptor  also  includes  a  few   other  op'miza'ons  
  • 26. Loan  applica'on  processing   Applica'on  by  user   Pre-­‐bureau  processing   Call  credit  bureau     Approved  /  refer  /  reject     Save  data    
  • 27. Loan  applica'on  processing   Applica'on  by  user   Applica'on  by  user   Pre-­‐bureau  processing   Pre-­‐bureau  processing   Call  credit  bureau   Call  credit  bureau       Approved  /  refer  /  reject   Approved  /  refer  /  reject       Save  data   Save  data      
  • 28. Loan  applica'on  processing   Applica'on  by  user   Pre-­‐bureau  processing   X  100  every   Call  credit  bureau     second   Approved  /  refer  /  reject     Save  data    
  • 29. Loan  applica'on  processing   Applica'on  by  user   Pre-­‐bureau  processing   Call  credit  bureau     Approved  /  refer  /  reject   Save  data      
  • 30. Loan  applica'on  processing   Applica'on  by  user   Pre-­‐bureau  processing   Tedious  in  your   Call  credit  bureau   typical  applica'on     server  (resort  to  JMS)   Approved  /  refer  /  reject   Save  data      
  • 31. Loan  applica'on  processing  –  with   Disruptor   Applica'on  by  user   Disruptor   Pre-­‐bureau  processing   Call  credit  bureau     Approved  /  refer  /  reject   Save  data      
  • 32. Loan  applica'on  processing  –  with   Disruptor   Applica'on  by  user   Disruptor   Handle  ‘forking’   Pre-­‐bureau  processing   Handle  parallel  users   Handle  ‘workflow’   Call  credit  bureau     Approved  /  refer  /  reject   Save  data      
  • 33. Loan  applica'on  processing  –  with   Disruptor   Disruptor<MyEvent>  disruptor  =  new  Disruptor<MyEvent>(…);     //read  data   disruptor.handleEventsWith(preBureauProcessing).  //first  do  this   then(callBureau).  //next  do  this   then(  approvedReferReject,  saveData);  //arer  that,  do  these  in  parallel     //run  disruptor   RingBuffer<ValueEvent>  ringBuffer  =  disruptor.start();     //write  (applica'on  by  user)   long  sequence  =  ringBuffer.next();   MyEvent    event  =  ringBuffer.get(sequence);   event.setValue(x);   ringBuffer.publish(sequence);    
  • 34. Batch  reading   Write   Write   Write  
  • 37. Useful  paUerns   •  PaUerns  I’ve  experimented  with   –  Not  ‘in  produc'on  yet’   –  Try  it  out  on  your  own  before  commisng   –   Don’t  sue  me  if  it  blows  J  
  • 41. Topic  replacement   •  Just  use  disruptor’s  ‘default  sesng’    
  • 43. Queue  replacement   •  Use  WorkerPool     WorkerPool<ValueEvent>  workerPool  =  new  WorkerPool<ValueEvent>(…);    workerPool.start(…)  ;  
  • 44. Actors   •  A  unit  of  concurrent  computa'on     •  From  wikipedia:   –  “…  in  response  to  a  message  that  it  receives,  an   actor  can  make  local  decisions,  create  more   actors,  send  more  messages,  and  determine  how   to  respond  to  the  next  message  received”  
  • 46. Actors   Actor  =  Worker  Pool  (Queue)  
  • 47. Actors   Actor  =  Worker  Pool  (Queue)  
  • 49. Replica'on   ‘Topic’  layout   JMS   JMS  messaging  over  network   Listener  
  • 50. Replica'on   ‘Topic’  layout   JMS   Guaranteed  delivery   JMS  messaging  over  network   Listener  
  • 51. Conclusion   •  Disruptor  –  interes'ng  and  ‘disrup've’   framework   •  Revenge  of  the  “object  oriented  programming”   model  J   •  Do  your  own  experiments   •  Check  out:   –  hUp://code.google.com/p/disruptor/   –  hUp://mar'nfowler.com/ar'cles/lmax.html   –  hUp://mechani's.blogspot.com/2011/07/dissec'ng-­‐ disruptor-­‐wiring-­‐up.html