Akka - Developing SEDA Based Applications
Upcoming SlideShare
Loading in...5

Akka - Developing SEDA Based Applications



Developing SEDA Based Applications using Akka.

Developing SEDA Based Applications using Akka.



Total Views
Views on SlideShare
Embed Views



8 Embeds 172

http://bdarfler.com 140
http://paper.li 22
http://www.linkedin.com 5
http://twitter.com 1
http://tweetedtimes.com 1
http://www.tumblr.com 1
http://safe.tumblr.com 1
http://thornydev.posterous.com 1


Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Akka - Developing SEDA Based Applications Akka - Developing SEDA Based Applications Presentation Transcript

    • AkkaDeveloping SEDA Based Applications
    • MeBen Darfler@bdarflerhttp://bdarfler.comSenior Software Engineer at Localytics
    • LocalyticsReal time mobile analytics platform40M+ events per day and growing rapidly3x growth over the past 3 monthsHeavy users of Scala/Akka/NoSqlWe are hiring (seriously, come talk to me)
    • LocalyicsHow to keep up with our growth?
    • Actor ModelLock free approach to concurrencyNo shared state between actorsAsynchronous message passingMailboxes to buffer incoming messages
    • AkkaConfigurable Dispatchers MailboxesFault Tolerant SupervisorsGreat community @jboner @viktorklang
    • Akka Performanthttp://blog.jayway.com/2010/08/10/yet-another-akka-benchmark/
    • SEDAStaged Event Driven Architecture"Decomposes a complex, event-drivenapplication into a set of stages connectedby queues." 1"The most fundamental aspect of the SEDAarchitecture is the programming model thatsupports stage-level backpressure and loadmanagement." 11. http://www.eecs.harvard.edu/~mdw/proj/seda/
    • Backpressure Whats the big deal?
    • BackpressureManditory to prevent OutOfMemoryError Messages backup in memory faster than they can be processedCassandra 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)
    • BackpressureMailboxescase class UnboundedMailbox(val blocking: Boolean = false) extends MailboxTypecase 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 MailboxTypeBackpressure MailboxBoundedMailbox(true, QUEUE_SIZE, Duration(-1, "millis"))
    • Stages How do we decompose the problem?
    • StagesOne actor class per stageShared dispatcherIndividually tunable I/O Bound CPU BoundEasier to reason aboutCode reuse
    • DispatchersThreadBasedDispatcher Binds one actor to its own threadExecutorBasedEventDrivenDispatcher Must be shared between actorsExecutorBasedEventDrivenWorkStealingDispatcher 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 StealingExecutorBasedEventDrivenWorkStealingDispatcher"Actors of the same type can be set up to share thisdispatcher and during execution time the differentactors will steal messages from other actors if theyhave less messages to process" 11. http://doc.akka.io/dispatchers-scala
    • Work StealingReally a work "donating" dispatcher "I have implemented a work stealing dispatcher forAkka actors. Although its called "work stealing" theimplementation actually behaves more as "workdonating" because the victim actor takes the initiative.I.e. it actually donates work to its thief, ratherthan having the thief steal work from the victim." 11. http://janvanbesien.blogspot.com/2010/03/load-balancing-actors-with-work.html
    • Work Stealing Doesnt that conflict with blocking mailboxes?
    • Work StealingSending actor will block on the receiving actorsmailbox 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 BalancingRouting.loadBalancerActor() Creates a new actor that forwards messages in a load balancing fashionInfiniteIterator CyclicIterator SmallestMailboxFirstIterator
    • Load BalancingDoesnt the load balancer need a blocking mailbox?
    • Load BalancingCant easily change the load balancers mailboxUse SmallestMailboxFirstIterator directlynew SmallestMailboxFirstIterator(List(actor, actor, actor))
    • Fault ToleranceSupervisors Restarts actors Stops after x times within y millisecondsRestart Strategies OneForOne AllForOne
    • Fault ToleranceGreat for transient issues Network failuresNot great for permanent issues OutOfMemoryError
    • Final Product// Actor creationval supervisor = Supervisor(SupervisorConfig( OneForOneStrategy(List(classOf[Exception]), RETRIES, WITH_IN_TIME), Supervise(myActors))defmyActors: List[Supervise] = { val mailbox = BoundedMailbox(true, QUEUE_SIZE, Duration(-1, "millis")) val dispatcher = Dispatchers.newExecutorBasedEventDrivenWorkStealingDispatcher( "my-dispatcher", 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 messageval actors = new SmallestMailboxFirstIterator(actorsFor(classOf[MyActor]).toList)def actor = actors.nextactor ! Message()
    • Thanks @bdarfler http://bdarfler.com