Akka smash-and-grab

829 views
729 views

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
829
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Akka smash-and-grab

  1. 1. Akka: The Smash and Grab Intro The Basics of Sane Concurrency Jeremy Pierre Yet Another Developer @ j14159twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  2. 2. Akka What? Don’t call it a framework So...? A toolkit for sane concurrency. • Not just about actors • Blocking is bad, event-based is good • Crashing is not the end of the worldtwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  3. 3. The Overview What I’ll Cover: • Actors and ActorSystems • Supervision(in passing) • Futures and Promises • Some interesting stuff with execution contexts, event buses and schedulerstwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  4. 4. The Overview What I’ll Cover: • Actors and ActorSystems • Supervision(in passing) • Futures and Promises • Some interesting stuff with execution contexts, event buses and schedulers What I’m Not Covering • Remoting • FSM • Routing/Dispatchers • IOtwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  5. 5. To help it all make sense... We use the Librarian Problem:• A Library has one Librarian but many Interns.• Interns do not know where to find specific books.• The Librarian can’t go find books for customers because they can then only help oneat a time.• If the Librarian tells the Interns where to find stuff, many book requests can behandled at the same time. twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  6. 6. Akka Actors The logical extreme of OOP and Information Hiding• There’s only one methodto make it do stuff(tell / !)• They’re purely event-based• They live in ActorSystems twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  7. 7. ActorSystem • They make ActorRefs • They’re the root of a hierarchy(think file system)twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  8. 8. ActorSystem • They make ActorRefs • They’re the root of a hierarchy(think file system)twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  9. 9. ActorSystem • They make ActorRefs • They’re the root of a hierarchy(think file system)twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  10. 10. Futures... ...let us do asynchronous stuff without an Actor But where’s the result?twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  11. 11. Futures... ...let us do asynchronous stuff without an Actor But where’s the result?twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  12. 12. Promises The “write” side of Futures But that looks kind of boring...twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  13. 13. Promises The “write” side of Futures But that looks kind of boring...twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  14. 14. One more Promisetwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  15. 15. Using the results of Future/Promise As you’d expect, this gives you another Future: This callback is for side-effecting:twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  16. 16. Event Bus and Scheduler EventBus is (very) simple pub-sub for Actors:twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  17. 17. Event Bus and Scheduler EventBus is (very) simple pub-sub for Actors: Scheduler?"Thread.sleep is never fine. Its like drowning a kitten." - @viktorklang twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  18. 18. Event Bus and Scheduler EventBus is (very) simple pub-sub for Actors: Scheduler makes stuff happen when you want it to:twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  19. 19. Asking and Piping import akka.pattern.asktwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  20. 20. Asking and Piping import akka.pattern.ask import akka.pattern.pipetwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  21. 21. ExecutionContext Futures and Promises need it • It basically hides a java.util.concurrent.Executor • Your ActorSystem’s dispatcher is one • You can create them via configuration or programmaticallytwitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  22. 22. Mix Them!Never block your ActorSystem’s threads for DB calls!twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
  23. 23. Thank You! Jeremy Pierre Yet Another Developer @j14159twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com

×