SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Akka
Developing SEDA Based
      Applications
Me
Ben Darfler

@bdarfler
http://bdarfler.com
Senior Software Engineer at Localytics
Localytics
Real time mobile analytics platform

40M+ events per day and growing rapidly

3x growth over the past 3 months

Heavy users of Scala/Akka/NoSql
We are hiring (seriously, come talk to me)
Localytics


How to keep up with our growth?
Actor Model
Lock free approach to concurrency
No shared state between actors
Asynchronous message passing
Mailboxes to buffer incoming messages
Akka
Configurable
 ● Dispatchers
 ● Mailboxes

Fault Tolerant
 ● Supervisors

Great community
 ● @jboner
 ● @viktorklang
Akka
                                       Performant




http://blog.jayway.com/2010/08/10/yet-another-akka-benchmark/
SEDA
Staged Event Driven Architecture

"Decomposes a complex, event-driven
application into a set of stages connected
by queues."               1




"The most fundamental aspect of the SEDA
architecture is the programming model that
supports stage-level backpressure and load
management."                   1




1. http://www.eecs.harvard.edu/~mdw/proj/seda/
Backpressure


     Whats the big deal?
Backpressure
Manditory to prevent OutOfMemoryError
 ● Messages backup in memory faster than they
   can be processed

Cassandra was seriously bitten by this
 ● Less crappy failure mode when swamped with
   inserts than "run out of memory and gc-storm
   to death" (CASSANDRA-401)
 ● Add backpressure to StorageProxy
   (CASSANDRA-685)
Backpressure
Mailboxes
case class UnboundedMailbox(val blocking: Boolean = false) extends MailboxType

case class BoundedMailbox(
  val blocking: Boolean = false,
  val capacity: Int = {
     if (Dispatchers.MAILBOX_CAPACITY < 0) Int.MaxValue
     else Dispatchers.MAILBOX_CAPACITY
   },
  val pushTimeOut: Duration = Dispatchers.MAILBOX_PUSH_TIME_OUT
) extends MailboxType



Backpressure Mailbox
BoundedMailbox(false, QUEUE_SIZE, Duration(-1, "millis"))
Stages


  How do we decompose the problem?
Stages
One actor class per stage

Shared dispatcher

Individually tunable
 ● I/O Bound
 ● CPU Bound

Easier to reason about

Code reuse
Dispatchers
ThreadBasedDispatcher
 ● Binds one actor to its own thread

ExecutorBasedEventDrivenDispatcher
 ● Must be shared between actors

ExecutorBasedEventDrivenWorkStealingDispatcher
 ● Must be shared between actors of the same type
Queues

  SEDA has a queue per stage model

  Akka actors have their own mailbox

  How do we evenly distribute work?
Work Stealing
ExecutorBasedEventDrivenWorkStealingDispatcher

"Actors of the same type can be set up to share this
dispatcher and during execution time the different
actors will steal messages from other actors if they
have less messages to process"            1




1. http://doc.akka.io/dispatchers-scala
Work Stealing
Really a work "donating" dispatcher

  "I have implemented a work stealing dispatcher for
Akka actors. Although its called "work stealing" the
implementation actually behaves more as "work
donating" because the victim actor takes the initiative.
I.e. it actually donates work to its thief, rather
than having the thief steal work from the victim."                                 1




1. http://janvanbesien.blogspot.com/2010/03/load-balancing-actors-with-work.html
Work Stealing


 Doesn't that conflict with blocking mailboxes?
Work Stealing
Sending actor will block on the receiving actors
mailbox before it can "donate"

Might be fixed in Akka 1.1
 ● I owe @viktorklang a test of his latest changes
Load Balancing


  Can we distribute work on the sender side?
Load Balancing
Routing.loadBalancerActor()
 ● Creates a new actor that forwards
   messages in a load balancing fashion

InfiniteIterator
 ● CyclicIterator
 ● SmallestMailboxFirstIterator
Load Balancing


Doesn't the load balancer need a blocking mailbox?
Load Balancing
Can't easily change the load balancer's mailbox

Use SmallestMailboxFirstIterator directly
new SmallestMailboxFirstIterator(List(actor, actor, actor))
Fault Tolerance
Supervisors
 ● Restarts actors
 ● Stops after x times within y milliseconds

Restart Strategies
 ● OneForOne
 ● AllForOne
Fault Tolerance
Great for transient issues
 ● Network failures

Not great for permanent issues
 ● OutOfMemoryError
Final Product
// Actor creation
val supervisor = Supervisor(SupervisorConfig(
   OneForOneStrategy(List(classOf[Exception]), RETRIES, WITH_IN_TIME),
   Supervise(myActors))

def
myActors
: List[Supervise] = {
  val mailbox = BoundedMailbox(false, QUEUE_SIZE, Duration(-1, "millis"))
  val dispatcher =
    Dispatchers.newExecutorBasedEventDrivenDispatcher(
    "my-dispatcher", 1, mailbox).setCorePoolSize(POOL_SIZE).build
  (1 to POOL_SIZE toList).foldRight(List[Supervise]()) {
    (i, list) =>
     Supervise(actorOf(new MyActor("my-actor-" + i, dispatcher)), Permanent) :: list
  }
}

// Sending a message
val actors = new SmallestMailboxFirstIterator(actorsFor(classOf[MyActor]).toList)
def actor = actors.next
actor ! Message()
Thanks

          @bdarfler
     http://bdarfler.com

Más contenido relacionado

La actualidad más candente

Scaling React and Redux at IOOF
Scaling React and Redux at IOOFScaling React and Redux at IOOF
Scaling React and Redux at IOOFVivian Farrell
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Hsuan Fu Lien
 
Learning React - I
Learning React - ILearning React - I
Learning React - IMitch Chen
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JSBinary Studio
 
React js Rahil Memon
React js Rahil MemonReact js Rahil Memon
React js Rahil MemonRahilMemon5
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactDejan Glozic
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners Varun Raj
 
001. Introduction about React
001. Introduction about React001. Introduction about React
001. Introduction about ReactBinh Quan Duc
 

La actualidad más candente (20)

React js
React jsReact js
React js
 
Scaling React and Redux at IOOF
Scaling React and Redux at IOOFScaling React and Redux at IOOF
Scaling React and Redux at IOOF
 
React.js
React.jsReact.js
React.js
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
React introduction
React introductionReact introduction
React introduction
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
React.js+Redux Workshops
React.js+Redux WorkshopsReact.js+Redux Workshops
React.js+Redux Workshops
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)
 
Learning React - I
Learning React - ILearning React - I
Learning React - I
 
React js
React jsReact js
React js
 
React js
React jsReact js
React js
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JS
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js Rahil Memon
React js Rahil MemonReact js Rahil Memon
React js Rahil Memon
 
reactJS
reactJSreactJS
reactJS
 
Breaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and ReactBreaking the Server-Client Divide with Node.js and React
Breaking the Server-Client Divide with Node.js and React
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
React js
React jsReact js
React js
 
001. Introduction about React
001. Introduction about React001. Introduction about React
001. Introduction about React
 
How to Redux
How to ReduxHow to Redux
How to Redux
 

Similar a Akka - Developing SEDA Based Applications

Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_groupSkills Matter
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den HoekRubiX BV
 
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsIntroduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsdatamantra
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsShashank L
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matterSkills Matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with AkkaMaciej Matyjas
 
Building large scale, job processing systems with Scala Akka Actor framework
Building large scale, job processing systems with Scala Akka Actor frameworkBuilding large scale, job processing systems with Scala Akka Actor framework
Building large scale, job processing systems with Scala Akka Actor frameworkVignesh Sukumar
 
Actor model in F# and Akka.NET
Actor model in F# and Akka.NETActor model in F# and Akka.NET
Actor model in F# and Akka.NETRiccardo Terrell
 
The Pillars Of Concurrency
The Pillars Of ConcurrencyThe Pillars Of Concurrency
The Pillars Of Concurrencyaviade
 
Unifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
Unifying Messaging, Queueing & Light Weight Compute Using Apache PulsarUnifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
Unifying Messaging, Queueing & Light Weight Compute Using Apache PulsarKarthik Ramasamy
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAPaolo Platter
 
Fundamentals of Akka - Webinar
Fundamentals of Akka - WebinarFundamentals of Akka - Webinar
Fundamentals of Akka - WebinarKnoldus Inc.
 
Let the alpakka pull your stream
Let the alpakka pull your streamLet the alpakka pull your stream
Let the alpakka pull your streamEnno Runne
 
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward
 

Similar a Akka - Developing SEDA Based Applications (20)

Akka (1)
Akka (1)Akka (1)
Akka (1)
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
 
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actorsIntroduction to concurrent programming with akka actors
Introduction to concurrent programming with akka actors
 
Introduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actorsIntroduction to concurrent programming with Akka actors
Introduction to concurrent programming with Akka actors
 
Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with Akka
 
Building large scale, job processing systems with Scala Akka Actor framework
Building large scale, job processing systems with Scala Akka Actor frameworkBuilding large scale, job processing systems with Scala Akka Actor framework
Building large scale, job processing systems with Scala Akka Actor framework
 
Actor model in F# and Akka.NET
Actor model in F# and Akka.NETActor model in F# and Akka.NET
Actor model in F# and Akka.NET
 
The Pillars Of Concurrency
The Pillars Of ConcurrencyThe Pillars Of Concurrency
The Pillars Of Concurrency
 
Unifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
Unifying Messaging, Queueing & Light Weight Compute Using Apache PulsarUnifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
Unifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKA
 
Fundamentals of Akka - Webinar
Fundamentals of Akka - WebinarFundamentals of Akka - Webinar
Fundamentals of Akka - Webinar
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
 
Akka.Net Overview
Akka.Net OverviewAkka.Net Overview
Akka.Net Overview
 
Let the alpakka pull your stream
Let the alpakka pull your streamLet the alpakka pull your stream
Let the alpakka pull your stream
 
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
Flink Forward SF 2017: Feng Wang & Zhijiang Wang - Runtime Improvements in Bl...
 

Último

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
 
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
 
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...apidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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.pptxMalak Abu Hammad
 
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
 
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
 
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 WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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 DevelopmentsTrustArc
 
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 MountPuma Security, LLC
 
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 MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

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...
 
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
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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
 
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
 
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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Akka - Developing SEDA Based Applications

  • 3. Localytics Real time mobile analytics platform 40M+ events per day and growing rapidly 3x growth over the past 3 months Heavy users of Scala/Akka/NoSql We are hiring (seriously, come talk to me)
  • 4. Localytics How to keep up with our growth?
  • 5. Actor Model Lock free approach to concurrency No shared state between actors Asynchronous message passing Mailboxes to buffer incoming messages
  • 6. Akka Configurable ● Dispatchers ● Mailboxes Fault Tolerant ● Supervisors Great community ● @jboner ● @viktorklang
  • 7. Akka Performant http://blog.jayway.com/2010/08/10/yet-another-akka-benchmark/
  • 8. SEDA Staged Event Driven Architecture "Decomposes a complex, event-driven application into a set of stages connected by queues." 1 "The most fundamental aspect of the SEDA architecture is the programming model that supports stage-level backpressure and load management." 1 1. http://www.eecs.harvard.edu/~mdw/proj/seda/
  • 9. Backpressure Whats the big deal?
  • 10. Backpressure Manditory to prevent OutOfMemoryError ● Messages backup in memory faster than they can be processed Cassandra was seriously bitten by this ● Less crappy failure mode when swamped with inserts than "run out of memory and gc-storm to death" (CASSANDRA-401) ● Add backpressure to StorageProxy (CASSANDRA-685)
  • 11. Backpressure Mailboxes case class UnboundedMailbox(val blocking: Boolean = false) extends MailboxType case class BoundedMailbox( val blocking: Boolean = false, val capacity: Int = { if (Dispatchers.MAILBOX_CAPACITY < 0) Int.MaxValue else Dispatchers.MAILBOX_CAPACITY }, val pushTimeOut: Duration = Dispatchers.MAILBOX_PUSH_TIME_OUT ) extends MailboxType Backpressure Mailbox BoundedMailbox(false, QUEUE_SIZE, Duration(-1, "millis"))
  • 12. Stages How do we decompose the problem?
  • 13. Stages One actor class per stage Shared dispatcher Individually tunable ● I/O Bound ● CPU Bound Easier to reason about Code reuse
  • 14. Dispatchers ThreadBasedDispatcher ● Binds one actor to its own thread ExecutorBasedEventDrivenDispatcher ● Must be shared between actors ExecutorBasedEventDrivenWorkStealingDispatcher ● Must be shared between actors of the same type
  • 15. Queues SEDA has a queue per stage model Akka actors have their own mailbox How do we evenly distribute work?
  • 16. Work Stealing ExecutorBasedEventDrivenWorkStealingDispatcher "Actors of the same type can be set up to share this dispatcher and during execution time the different actors will steal messages from other actors if they have less messages to process" 1 1. http://doc.akka.io/dispatchers-scala
  • 17. Work Stealing Really a work "donating" dispatcher "I have implemented a work stealing dispatcher for Akka actors. Although its called "work stealing" the implementation actually behaves more as "work donating" because the victim actor takes the initiative. I.e. it actually donates work to its thief, rather than having the thief steal work from the victim." 1 1. http://janvanbesien.blogspot.com/2010/03/load-balancing-actors-with-work.html
  • 18. Work Stealing Doesn't that conflict with blocking mailboxes?
  • 19. Work Stealing Sending actor will block on the receiving actors mailbox before it can "donate" Might be fixed in Akka 1.1 ● I owe @viktorklang a test of his latest changes
  • 20. Load Balancing Can we distribute work on the sender side?
  • 21. Load Balancing Routing.loadBalancerActor() ● Creates a new actor that forwards messages in a load balancing fashion InfiniteIterator ● CyclicIterator ● SmallestMailboxFirstIterator
  • 22. Load Balancing Doesn't the load balancer need a blocking mailbox?
  • 23. Load Balancing Can't easily change the load balancer's mailbox Use SmallestMailboxFirstIterator directly new SmallestMailboxFirstIterator(List(actor, actor, actor))
  • 24. Fault Tolerance Supervisors ● Restarts actors ● Stops after x times within y milliseconds Restart Strategies ● OneForOne ● AllForOne
  • 25. Fault Tolerance Great for transient issues ● Network failures Not great for permanent issues ● OutOfMemoryError
  • 26. Final Product // Actor creation val supervisor = Supervisor(SupervisorConfig( OneForOneStrategy(List(classOf[Exception]), RETRIES, WITH_IN_TIME), Supervise(myActors)) def myActors : List[Supervise] = { val mailbox = BoundedMailbox(false, QUEUE_SIZE, Duration(-1, "millis")) val dispatcher = Dispatchers.newExecutorBasedEventDrivenDispatcher( "my-dispatcher", 1, mailbox).setCorePoolSize(POOL_SIZE).build (1 to POOL_SIZE toList).foldRight(List[Supervise]()) { (i, list) => Supervise(actorOf(new MyActor("my-actor-" + i, dispatcher)), Permanent) :: list } } // Sending a message val actors = new SmallestMailboxFirstIterator(actorsFor(classOf[MyActor]).toList) def actor = actors.next actor ! Message()
  • 27. Thanks @bdarfler http://bdarfler.com