SlideShare a Scribd company logo
Akka Actors




@Sander_Mak
Akka
              Part of



              stack

Written in Scala
With officially supported Java API
Akka

     ‘s premise
It’s too hard to write systems that are:

  Concurrent & Correct
  Highly scalable
  Fault-tolerant
Akka

   2.0
Actors
Software Transactional Memory
Dataflow concurrency
Futures
Akka
who uses



           ?
               traffic management
Actors
Inspired by               :


    Asynchronous message passing
    Scale up, scale out
    Fault-tolerant (‘let it crash’)
Actors
How to define an actor?
                         ~400 bytes




                         Local state

                          Behavior




               mailbox
Actors
How to define an actor?
                              ~400 bytes
  Create more actors
  Send messages
  Modify state                Local state

  Modify behavior              Behavior




                    mailbox
Actors
How to define an actor?


class MyFirstActor extends Actor {
  var total = 0

    def receive = {
      case MyMessage(payload) => println(“Received: “ + payload”)
      case countMessage: Int => total += countMessage
      case _ => println("Unknown message")
    }
}
Actors
Dispatcher: contains executor strategy




                           Local state
       Event-driven
                           Behavior




                 mailbox
Actors and Fork/Join
Ping/pong messages (no processing)




                   Improved
 48
                 JSR-166 build (     ?)
cores
Demo
                 NearestCityActor
                 NearestCityActor
                  NearestCityActor
                  NearestCityActor



  RoundRobin                       Result
    Router                     ListenerActor



Messages with cities             Print results
Supervision
Hierarchical supervision
 Child actors supervised by parent
Trap exceptions and apply recovery
Error Kernel pattern

 Actor 1     create child
                actor
                            Actor 2   dangerous
                                      operation
  critical
   state      supervise




Distinguish scratch and critical state
Supervision
class GuardianActor extends Actor {

    def supervisorStrategy = OneForOneStrategy({
        case _:CompanyBankruptException    => Stop
        case _:InvalidStateException       => Restart
        case _:ServiceUnavailableException => Resume
        case _                             => Escalate
     }, maxNrOfRetries = 3, 5.seconds)

    def receive = {
      ...
    }
}




             Actor may implement
            preRestart & postRestart
Remote actors
Dispatchers for scale-up, remote actors for scala-out


   Machine A                           Machine B
                    actor2 ! SomeMsg
      Actor 1                           Actor 2
                     Netty, Protobuf



      Router                            Actor 3


   Actor creation
   Supervision
   Remote deploy through config (no code change)
Remote actors
Creating 10 actors on 2 nodes with a router
 akka	
  {
 	
  	
  actor	
  {
 	
  	
  	
  	
  deployment	
  {
 	
  	
  	
  	
  	
  	
  /serviceA/aggregation	
  {
 	
  	
  	
  	
  	
  	
  	
  	
  router	
  =	
  "round-­‐robin"
 	
  	
  	
  	
  	
  	
  	
  	
  nr-­‐of-­‐instances	
  =	
  10
 	
  	
  	
  	
  	
  	
  	
  	
  target	
  {
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  nodes	
  =	
  ["akka://app@10.0.0.2:2552",	
  "akka://app@10.0.0.3:2552"]
 	
  	
  	
  	
  	
  	
  	
  	
  }
 	
  	
  	
  	
  	
  	
  }
 	
  	
  	
  	
  }
 	
  	
  }
 }




Looking up a remote actor
 val	
  actor	
  =	
  
 	
  	
  	
  context.actorFor("akka://actorSystemName@10.0.0.1:2552/user/actorName")
Blocking
Actors lift some ForkJoin restrictions
    Remoting possible
    Recursive decomposition optional
    Fault-tolerant

Still, there are restrictions similar to ForkJoin tasks

    No blocking IO
    No explicit locking
    No shared memory writes
Async IO
 Based on composable Futures

Serve http
                mini               akka-Spray


Consume http
               async-http-client


Persistence
                hammersmith
Async IO
          Based on Java NIO


Akka IO

   Immutable abstractions on top of:
     Channels
     Streams (Iteratee based)
   Bridges (low-level) async IO and actors
Async IO
       Practical application:




  JMeter => 1 user, 1 thread     Gatling => 1 user, 1 actor
+ blocking IO                   + async-http-client

= OutOfMemory errors            =
  or clustering necessary

  time drift in results
Async IO
       Practical application:




  JMeter => 1 user, 1 thread     Gatling => 1 user, 1 actor
+ blocking IO                   + async-http-client

= OutOfMemory errors            =
  or clustering necessary

  time drift in results
Is that all?
             Finite State Machine          Akka TestKit




 core
          Scheduler                 Event Bus




modules
Is that all?
                   Typesafe
                   Console




Commercial
subscription
Questions?


      Code @ bit.ly/bejug-akka

More Related Content

KEY
Java 7: Fork/Join, Invokedynamic and the future
PDF
Introduction to Actor Model and Akka
PPTX
Introduction to Akka - Atlanta Java Users Group
PDF
The dark side of Akka and the remedy
ODP
Open Source Compiler Construction for the JVM
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PPT
Java, Ruby & Rails
PDF
What is Serialization in Java? | Java Tutorial | Edureka
Java 7: Fork/Join, Invokedynamic and the future
Introduction to Actor Model and Akka
Introduction to Akka - Atlanta Java Users Group
The dark side of Akka and the remedy
Open Source Compiler Construction for the JVM
Java 7 Whats New(), Whats Next() from Oredev
Java, Ruby & Rails
What is Serialization in Java? | Java Tutorial | Edureka

What's hot (19)

PDF
Advanced akka features
PDF
Actor Model Akka Framework
PPTX
Java 8 parallel stream
PDF
Akka - A Brief Intro
PPTX
JAVA 8 Parallel Stream
PDF
Akka Futures and Akka Remoting
PDF
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
PDF
Working With Concurrency In Java 8
PDF
The internet of (lego) trains
ODP
Unit Testing and Coverage for AngularJS
PDF
Angular Weekend
PPTX
Testing in Scala. Adform Research
PDF
Intro to JavaScript
KEY
Grand Central Dispatch
PDF
Concurrency
PPTX
PPTX
Headless fragments in Android
PPTX
Understanding react hooks
PDF
Java 9, JShell, and Modularity
Advanced akka features
Actor Model Akka Framework
Java 8 parallel stream
Akka - A Brief Intro
JAVA 8 Parallel Stream
Akka Futures and Akka Remoting
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
Working With Concurrency In Java 8
The internet of (lego) trains
Unit Testing and Coverage for AngularJS
Angular Weekend
Testing in Scala. Adform Research
Intro to JavaScript
Grand Central Dispatch
Concurrency
Headless fragments in Android
Understanding react hooks
Java 9, JShell, and Modularity
Ad

Viewers also liked (20)

PPS
____,___
PDF
Selecting a Digital Banking Platform 2017-2018
PDF
Onestival pres
PPT
Presentation2[1]
PDF
Roadmap to WordPress Accessibility CSUN 2014
PPTX
11 necto installation_ready
PPT
Aim Presentation
DOC
Klimatstrategimall
PPT
Kosvenie rechevie akty
PPT
Prioritas Diklat
PDF
Cross-Build Injection attacks: how safe is your Java build?
KEY
PPT
Teenager
PPTX
Unmanned Video citizin services
PPT
How is my Artist Marketed??
PPT
MVC CSRF Protection
PPT
William turner
PPT
Halloween
PDF
Google Doc Ch4
____,___
Selecting a Digital Banking Platform 2017-2018
Onestival pres
Presentation2[1]
Roadmap to WordPress Accessibility CSUN 2014
11 necto installation_ready
Aim Presentation
Klimatstrategimall
Kosvenie rechevie akty
Prioritas Diklat
Cross-Build Injection attacks: how safe is your Java build?
Teenager
Unmanned Video citizin services
How is my Artist Marketed??
MVC CSRF Protection
William turner
Halloween
Google Doc Ch4
Ad

Similar to Akka (BeJUG) (20)

PDF
Building Massively Scalable application with Akka 2.0
KEY
Introduction to Actor Model and Akka
PDF
Akka lsug skills matter
PDF
Scaling Web Apps with Akka
PPTX
Akka Actors
PDF
Actor, an elegant model for concurrent and distributed computation
PDF
Introducing Akka
PDF
Introducingakkajavazone2012 120914094033-phpapp02
PDF
Build Cloud Applications with Akka and Heroku
PDF
Building Massively Scalable Applications With Akka
PDF
Akka vikas hazrati
PDF
Akka 2.0 Reloaded
PDF
Akka knolx
KEY
Akka london scala_user_group
PDF
Introducing Akka
PPTX
Scale up your thinking
PDF
Akka and futures
PPTX
Nairobi JVM meetup : Introduction to akka
 
PPTX
Real world Scala hAkking NLJUG JFall 2011
PDF
Akka (1)
Building Massively Scalable application with Akka 2.0
Introduction to Actor Model and Akka
Akka lsug skills matter
Scaling Web Apps with Akka
Akka Actors
Actor, an elegant model for concurrent and distributed computation
Introducing Akka
Introducingakkajavazone2012 120914094033-phpapp02
Build Cloud Applications with Akka and Heroku
Building Massively Scalable Applications With Akka
Akka vikas hazrati
Akka 2.0 Reloaded
Akka knolx
Akka london scala_user_group
Introducing Akka
Scale up your thinking
Akka and futures
Nairobi JVM meetup : Introduction to akka
 
Real world Scala hAkking NLJUG JFall 2011
Akka (1)

More from Sander Mak (@Sander_Mak) (20)

PDF
Scalable Application Development @ Picnic
PDF
Coding Your Way to Java 13
PDF
Coding Your Way to Java 12
PDF
Java Modularity: the Year After
PDF
Desiging for Modularity with Java 9
PDF
Modules or microservices?
PDF
Migrating to Java 9 Modules
PDF
Java 9 Modularity in Action
PDF
Java modularity: life after Java 9
PDF
Provisioning the IoT
PDF
Event-sourced architectures with Akka
PDF
TypeScript: coding JavaScript without the pain
PDF
The Ultimate Dependency Manager Shootout (QCon NY 2014)
PDF
Modular JavaScript
PDF
Modularity in the Cloud
KEY
Scala & Lift (JEEConf 2012)
KEY
Hibernate Performance Tuning (JEEConf 2012)
PDF
Fork Join (BeJUG 2012)
KEY
Fork/Join for Fun and Profit!
KEY
Kscope11 recap
Scalable Application Development @ Picnic
Coding Your Way to Java 13
Coding Your Way to Java 12
Java Modularity: the Year After
Desiging for Modularity with Java 9
Modules or microservices?
Migrating to Java 9 Modules
Java 9 Modularity in Action
Java modularity: life after Java 9
Provisioning the IoT
Event-sourced architectures with Akka
TypeScript: coding JavaScript without the pain
The Ultimate Dependency Manager Shootout (QCon NY 2014)
Modular JavaScript
Modularity in the Cloud
Scala & Lift (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)
Fork Join (BeJUG 2012)
Fork/Join for Fun and Profit!
Kscope11 recap

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
A Presentation on Artificial Intelligence
PDF
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Weekly Chronicles - August'25 Week I
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
A Presentation on Artificial Intelligence
KodekX | Application Modernization Development

Akka (BeJUG)

  • 2. Akka Part of stack Written in Scala With officially supported Java API
  • 3. Akka ‘s premise It’s too hard to write systems that are: Concurrent & Correct Highly scalable Fault-tolerant
  • 4. Akka 2.0 Actors Software Transactional Memory Dataflow concurrency Futures
  • 5. Akka who uses ? traffic management
  • 6. Actors Inspired by : Asynchronous message passing Scale up, scale out Fault-tolerant (‘let it crash’)
  • 7. Actors How to define an actor? ~400 bytes Local state Behavior mailbox
  • 8. Actors How to define an actor? ~400 bytes Create more actors Send messages Modify state Local state Modify behavior Behavior mailbox
  • 9. Actors How to define an actor? class MyFirstActor extends Actor { var total = 0 def receive = { case MyMessage(payload) => println(“Received: “ + payload”) case countMessage: Int => total += countMessage case _ => println("Unknown message") } }
  • 10. Actors Dispatcher: contains executor strategy Local state Event-driven Behavior mailbox
  • 11. Actors and Fork/Join Ping/pong messages (no processing) Improved 48 JSR-166 build ( ?) cores
  • 12. Demo NearestCityActor NearestCityActor NearestCityActor NearestCityActor RoundRobin Result Router ListenerActor Messages with cities Print results
  • 13. Supervision Hierarchical supervision Child actors supervised by parent Trap exceptions and apply recovery Error Kernel pattern Actor 1 create child actor Actor 2 dangerous operation critical state supervise Distinguish scratch and critical state
  • 14. Supervision class GuardianActor extends Actor { def supervisorStrategy = OneForOneStrategy({ case _:CompanyBankruptException => Stop case _:InvalidStateException => Restart case _:ServiceUnavailableException => Resume case _ => Escalate }, maxNrOfRetries = 3, 5.seconds) def receive = { ... } } Actor may implement preRestart & postRestart
  • 15. Remote actors Dispatchers for scale-up, remote actors for scala-out Machine A Machine B actor2 ! SomeMsg Actor 1 Actor 2 Netty, Protobuf Router Actor 3 Actor creation Supervision Remote deploy through config (no code change)
  • 16. Remote actors Creating 10 actors on 2 nodes with a router akka  {    actor  {        deployment  {            /serviceA/aggregation  {                router  =  "round-­‐robin"                nr-­‐of-­‐instances  =  10                target  {                    nodes  =  ["akka://app@10.0.0.2:2552",  "akka://app@10.0.0.3:2552"]                }            }        }    } } Looking up a remote actor val  actor  =        context.actorFor("akka://actorSystemName@10.0.0.1:2552/user/actorName")
  • 17. Blocking Actors lift some ForkJoin restrictions Remoting possible Recursive decomposition optional Fault-tolerant Still, there are restrictions similar to ForkJoin tasks No blocking IO No explicit locking No shared memory writes
  • 18. Async IO Based on composable Futures Serve http mini akka-Spray Consume http async-http-client Persistence hammersmith
  • 19. Async IO Based on Java NIO Akka IO Immutable abstractions on top of: Channels Streams (Iteratee based) Bridges (low-level) async IO and actors
  • 20. Async IO Practical application: JMeter => 1 user, 1 thread Gatling => 1 user, 1 actor + blocking IO + async-http-client = OutOfMemory errors = or clustering necessary time drift in results
  • 21. Async IO Practical application: JMeter => 1 user, 1 thread Gatling => 1 user, 1 actor + blocking IO + async-http-client = OutOfMemory errors = or clustering necessary time drift in results
  • 22. Is that all? Finite State Machine Akka TestKit core Scheduler Event Bus modules
  • 23. Is that all? Typesafe Console Commercial subscription
  • 24. Questions? Code @ bit.ly/bejug-akka