Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Akka in action - W-JAX 2012

hseeberger
November 08, 2012

Akka in action - W-JAX 2012

hseeberger

November 08, 2012
Tweet

More Decks by hseeberger

Other Decks in Technology

Transcript

  1. What is Akka? • Akka is a mountain in northern

    Sweden • Akka is part of the Typesafe Stack
  2. What is Akka? • Akka is a mountain in northern

    Sweden • Akka is part of the Typesafe Stack • Akka is a toolkit and runtime for scalable systems
  3. What is scalability? • Ability of a system to handle

    growing work or • its ability to be enlarged to accommodate growth.
  4. Akka’s vision • Simpler concurrency (scale up) • Simpler distribution

    (scale out) • Simpler fault-tolerance (self healing)
  5. Akka’s vision • Simpler concurrency (scale up) • Simpler distribution

    (scale out) • Simpler fault-tolerance (self healing) • All of that with a single unified programming model
  6. The Akka toolkit • Akka runs on the JVM •

    Akka can be used from Java and Scala
  7. The Akka toolkit • Akka runs on the JVM •

    Akka can be used from Java and Scala • Akka can be integrated with common infrastructure, e.g. Spring, Camel, ZeroMQ, etc.
  8. What’s inside the toolbox? • Actors • Agents • Dataflow

    concurrency • Software Transactional Memory (STM)
  9. What is an actor? • Carl Hewitt (1973): Fundamental unit

    of computation • Behavior - react on messages it receives
  10. What is an actor? • Carl Hewitt (1973): Fundamental unit

    of computation • Behavior - react on messages it receives • State - shielded from the rest of the world, no need for synchronization
  11. What is an actor? • Carl Hewitt (1973): Fundamental unit

    of computation • Behavior - react on messages it receives • State - shielded from the rest of the world, no need for synchronization • Communication - interact with other actors exclusively via messages
  12. What is an actor? • Carl Hewitt (1973): Fundamental unit

    of computation • Behavior - react on messages it receives • State - shielded from the rest of the world, no need for synchronization • Communication - interact with other actors exclusively via messages • “One actor is no actor” - they come in systems
  13. Other notions of an actor • Implementation of message passing

    concurrency • Isolated lightweight processes
  14. Other notions of an actor • Implementation of message passing

    concurrency • Isolated lightweight processes • Asynchronous and non-blocking
  15. Receive messages public class Hello extends UntypedActor { @Override public

    void onReceive(Object message) { System.out.println("Hello, world!"); } }
  16. Receive messages public class Hello extends UntypedActor { public int

    count = 0; @Override public void onReceive(Object message) { count += 1; System.out.println( "Hello for the " + count + " time!" ); } }
  17. Receive messages public class Hello extends UntypedActor { public int

    count = 0; @Override public void onReceive(Object message) { count += 1; System.out.println( "Hello for the " + count + " time!" ); } } One at a time
  18. Receive messages public class Hello extends UntypedActor { public int

    count = 0; @Override public void onReceive(Object message) { count += 1; System.out.println( "Hello for the " + count + " time!" ); } } One at a time Thread-safe
  19. Embrace failure • Let it crash! • Supervision: Like in

    real life, parents supervise their children
  20. Embrace failure • Let it crash! • Supervision: Like in

    real life, parents supervise their children • Depending on the parent’s supervisor strategy, failing actors can get stopped, restarted or resumed
  21. The HakkyHour bar • Our drinks: Akkarita, MaiPlay, PinaScalada •

    Our actors: guests, waiters, head waiter, barkeepers
  22. The HakkyHour bar • Our drinks: Akkarita, MaiPlay, PinaScalada •

    Our actors: guests, waiters, head waiter, barkeepers • Our messages: Order, drink served, complaint, etc.
  23. The HakkyHour bar • Our drinks: Akkarita, MaiPlay, PinaScalada •

    Our actors: guests, waiters, head waiter, barkeepers • Our messages: Order, drink served, complaint, etc. • Our failures: Guest drunk, waiter frustrated
  24. Benefits of using Akka actors • You don’t have to

    deal with low-level concurrency details
  25. Benefits of using Akka actors • You don’t have to

    deal with low-level concurrency details • You can manage failures easily
  26. Benefits of using Akka actors • You don’t have to

    deal with low-level concurrency details • You can manage failures easily • Distribution is just a deployment decision (not covered here)