introduction to akka
DESCRIPTION
The topconf 2013 introduction to actors with AkkaTRANSCRIPT
![Page 2: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/2.jpg)
Moores law
1971 today19902300
2,6 billions
1 million
![Page 3: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/3.jpg)
Oh, No Problems!
![Page 4: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/4.jpg)
Oh No, Problems!
• Race conditions
• Data corruption
• Deadlocks
• Thread contention
• Livelocks
• Priority Inversion
![Page 5: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/5.jpg)
Concurrency is HARD• To write
• To test
• To debug
• To reason about
We need a better model!
![Page 6: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/6.jpg)
![Page 7: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/7.jpg)
A
B C
D
EF
![Page 8: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/8.jpg)
ACTORSevent drivensystems with
![Page 9: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/9.jpg)
![Page 10: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/10.jpg)
Inbox
Behaviour
State
The only way to interact from
outside
![Page 11: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/11.jpg)
• Single execution flow model
• No shared _mutable_ state
• Lightweight
• Loose coupling
• Easy to test
![Page 12: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/12.jpg)
Actor A Actor B
![Page 13: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/13.jpg)
Actor A Actor B
One way communication
![Page 14: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/14.jpg)
Actor A Actor B
React, don’t wait
![Page 15: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/15.jpg)
Actor AActor B1
Load balancing
Actor B2
router
![Page 16: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/16.jpg)
Actor A Actor F (filter)
Pipe/Filter
Actor B
![Page 17: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/17.jpg)
Actor A Actor B (chef)
ParallellizeActor C1
Actor C2
Actor C2
![Page 18: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/18.jpg)
• No work, no thread used!
• Async - never actively wait
• Loose coupling
![Page 19: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/19.jpg)
A
B C
D
EF
JVM
![Page 20: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/20.jpg)
A
B C
D
EF
JVM 1 JVM 2
![Page 21: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/21.jpg)
• Two actors on one core
• Two actors on separate cores
• Two actors on separate servers
The same same
![Page 22: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/22.jpg)
Error handlingin Actor systems
![Page 23: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/23.jpg)
![Page 24: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/24.jpg)
• Leaking information between tiers
• Impossible to detect simultaneous errors
• The receiver does not know how to handle the errors!
Traditional model
![Page 25: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/25.jpg)
Actor X
(parent)
Actor A
Actor Z
Error handling with Actors
![Page 26: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/26.jpg)
Actor X
(parent)
Actor A
Actor Z
Error handling with Actors
![Page 27: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/27.jpg)
Actor X
Actor A
Actor Z
Error handling with Actors
![Page 28: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/28.jpg)
• Compartmentilization
• What goes back is explicit
• Separating error handling and business logic
• Can detect simultaneous errors
”Supervision”
![Page 29: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/29.jpg)
• STM
• Remoting
• Clustring with no SPoF
• MQs integration
• Eventbus
Wait, there is more!
akka.ioWebsite:
But
![Page 31: Introduction to Akka](https://reader034.vdocument.in/reader034/viewer/2022042521/55838a2ad8b42a9e528b47ad/html5/thumbnails/31.jpg)
• Simple but powerful model
• Lightweight and fast
• Loose coupling
• Resiliency
Recap
Johan Andrén [email protected] | @apnylle