akka: the smash and grab introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • if the...
TRANSCRIPT
![Page 1: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/1.jpg)
@
Jeremy PierreYet Another Developer
j14159
The Basics of Sane Concurrency
Akka:The Smash and Grab Intro
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
![Page 2: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/2.jpg)
Don’t call it a framework
Akka What?
So...?
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
A toolkit for sane concurrency.• Not just about actors• Blocking is bad, event-based is good• Crashing is not the end of the world
![Page 3: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/3.jpg)
The Overview
• Actors and ActorSystems• Supervision(in passing)• Futures and Promises• Some interesting stuff with execution contexts, event buses and schedulers
What I’ll Cover:
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
![Page 4: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/4.jpg)
The Overview
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
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• IO
![Page 5: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/5.jpg)
We use the Librarian Problem:
To help it all make sense...
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
• 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 one
at a time.
• If the Librarian tells the Interns where to find stuff, many book requests can be
handled at the same time.
![Page 6: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/6.jpg)
The logical extreme of OOP and Information Hiding
Akka Actors
• There’s only one method to 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
![Page 7: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/7.jpg)
ActorSystem
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
• They make ActorRefs• They’re the root of a hierarchy(think file system)
![Page 8: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/8.jpg)
ActorSystem
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
• They make ActorRefs• They’re the root of a hierarchy(think file system)
![Page 9: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/9.jpg)
ActorSystem
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
• They make ActorRefs• They’re the root of a hierarchy(think file system)
![Page 10: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/10.jpg)
...let us do asynchronous stuff without an Actor
Futures...
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
But where’s the result?
![Page 11: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/11.jpg)
...let us do asynchronous stuff without an Actor
Futures...
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
But where’s the result?
![Page 12: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/12.jpg)
Promises
The “write” side of Futures
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
But that looks kind of boring...
![Page 13: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/13.jpg)
Promises
The “write” side of Futures
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
But that looks kind of boring...
![Page 14: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/14.jpg)
One more Promise
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
![Page 15: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/15.jpg)
Using the results of Future/Promise
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
As you’d expect, this gives you another Future:
This callback is for side-effecting:
![Page 16: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/16.jpg)
Event Bus and Scheduler
EventBus is (very) simple pub-sub for Actors:
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
![Page 17: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/17.jpg)
Event Bus and Scheduler
EventBus is (very) simple pub-sub for Actors:
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
Scheduler?
"Thread.sleep is never fine. It's like drowning a kitten." - @viktorklang
![Page 18: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/18.jpg)
Event Bus and Scheduler
EventBus is (very) simple pub-sub for Actors:
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
Scheduler makes stuff happen when you want it to:
![Page 19: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/19.jpg)
Asking and Piping
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
import akka.pattern.ask
![Page 20: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/20.jpg)
Asking and Piping
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
import akka.pattern.ask
import akka.pattern.pipe
![Page 21: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/21.jpg)
Futures and Promises need it
ExecutionContext
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
• It basically hides a java.util.concurrent.Executor• Your ActorSystem’s dispatcher is one• You can create them via configuration or programmatically
![Page 22: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/22.jpg)
Mix Them!
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
Never block your ActorSystem’s threads for DB calls!
![Page 23: Akka: The Smash and Grab Introfiles.meetup.com/1795549/akka-smash-and-grab.pdf · • If the Librarian tells the Interns where to find stuff, many book requests can be handled at](https://reader034.vdocuments.us/reader034/viewer/2022050512/5f9cc07bb563e643145d2fa7/html5/thumbnails/23.jpg)
@
Thank You!
twitter.com/hootsuite facebook.com/hootsuite slideshare.com/hootsuite blog.hootsuite.com
Jeremy PierreYet Another Developer j14159