SlideShare a Scribd company logo
1 of 27
Download to read offline
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

More Related Content

What's hot

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
 

What's hot (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 to 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 to 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...
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 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
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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 ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

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