Friday Links 0.0.7 - Akka.net

This is based on an email I send my .NET team at work

Happy FridayMonday,

This morning I want to talk real quick about Akka.net

Akka.net is a port of a JVM project for implementing multi-threading and concurrency using the actor model.

In the actor model, you create lots of small classes that represent Actors: an actor performs a single operation, like “download this file” or “calculate this sum”. The actors communicate with each other by sending immutable messages back and forth.

Thread safety

Conceptually, each actor runs on its own thread, though this is certainly not true in practice. Many actor systems support millions of actors: each of them can’t have their own thread!

The message sending approach helps you avoid a lot of common multi-threading issues. Each actor can only process one message at a time: subsequent messages are stored in a queue. There is also no global state: all the state for an actor is contained within its own class. This keeps multiple threads from deadlocking on shared resources or causing race conditions with data access.

Distributed

Actor model systems help you easily support distributed computing. Whether or not an actor is running within the same process, another process, or even a whole other computer is transparent to you via the message sending API. You just say that you want to tell the DownloadActor to get a certain file: you don’t need to know if its running in the same process or another server.

Supervision

The actor system is usually set up as a tree, where higher level actors supervise lower level actors. If a lower level actor encounters an exception, the error is passed up to its supervisor who can decide what to do. You can restart the actor, ignore it, or pass the error up to your parent. Supervision helps the system become resilient to errors and self-healing.

Scaling

Actor systems are also really scalable. In addition to being able to spread out over multiple machines, actors can be dynamically created and destroyed to scale up to meet demand. You can set up Router actors that route messages to a variable number of children, thereby spreading the load out over multiple threads or servers.

I’ve been reading through this tutorial and found it to be a great introduction to most of the concepts in Akka.NET: Akka.NET Bootcamp

Here’s my demo app to download podcasts: https://github.com/akatakritos/AkkaPodcasts

If we get some projects that require large amounts of parallelism or distributed computing, I think Akka.NET would be a really good technology choice.