Download - Introduction to Actor Programming
![Page 1: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/1.jpg)
Introduction to Actor Programming
Wilson de Carvalho
![Page 2: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/2.jpg)
History
● The history of Actors goes back to the 70s, being originally proposed for Erlang;
● Emerged as a way to get scores of machines/CPUs to work together to solve large problems;
● Erlang + Actors used in AXD301, an Ericsson product that achieves nine nines of reliability.
![Page 3: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/3.jpg)
Pitfalls in multithreading
● Thread starvation: all threads busy or all deadlocked. User may think system is ok.
● Race conditions: shared data changed by multiple threads simultaneously. Internal logic can be subverted.
● Deadlock: thread 1 locks resource A, thread 2 resource B, then as 2 attempts to lock A and 1 lock B, we have a deadlock.
![Page 4: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/4.jpg)
Main idea
● Message passing;● Actors do not share state;● Actors only communicate through immutable
messages;● Actors do not talk to each other directly but
through actor references.
![Page 5: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/5.jpg)
Why better?
● Not necessary:○ Manage locks;○ Think about how to protect shared data;○ Scale shared mutable state solution (tough job!).
● More protected from deadlocks, race conditions and starvation;
● Inside an actor we're safe.
![Page 6: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/6.jpg)
Example
![Page 7: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/7.jpg)
Example: sharing state
![Page 8: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/8.jpg)
Example: message passing
1. Immutable messages
2. Asynchronous requests
3. Addresses instead of references
AddressTo(printOffice)
AddressTo(ticketAgent)
![Page 9: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/9.jpg)
Message passing x Function calling
![Page 10: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/10.jpg)
Fault tolerance
![Page 11: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/11.jpg)
Scaling up
● 4096 threads per GB in Linux x64 (stack size is 256kB)
● ~2.7 million actors per GB in Akka
![Page 12: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/12.jpg)
Scaling out
![Page 13: Introduction to Actor Programming](https://reader038.vdocument.in/reader038/viewer/2022110201/55cdf5ebbb61eb881b8b4824/html5/thumbnails/13.jpg)
References
- Books:- Actors in Scala- Akka In Action- Programming in Scala 2ed