Actor System from the Ground Up – Live Coding Session

Meet NetworkedAssets. This time: @ ANGACOM, 30 May – 1 June, Cologne
May 30, 2017
DevOps at Atlassian
June 2, 2017
Show all

Actor System from the Ground Up – Live Coding Session

Through almost one year of using Akka I have familiarized myself with its API. I have learned its strong sides and its quirks. But the internals, the way Akka achieves its nonblockingness and amazing performance, remained in the realm of unicorns and sun.misc.Unsafe. Finally, I decided to have a look under the hood. Three main questions bothered me:

  • How can multiple threads send messages to the same receiver (put them in the same mailbox) without ever getting in each other’s way? How can it be achieved without locking the mailbox?
  • What to do with threads which aren’t serving any actor at the moment? How to wake them up when needed?
  • How to ensure that two threads aren’t serving the same actor simultaneously?

Guess what I’ve found inside Akka: lots of sun.misc.Unsafe! But once I’d found my answers, it turned out they are much simpler than I expected (and they don’t contain the word Unsafe). In fact, the basic principles of implementing an actor system in Java/Scala turned out to be so simple, that I could do it myself. And that’s exactly what I did!

Furthermore, I decided to share it with my colleagues during our weekly Knowledge Sharing session, where I conducted two hours long live coding session – enough to implement Neo and Mr Smiths as actors. If you have a few spare hours for learning, I encourage you to try implementing a simple actor system from the ground up yourself. If you don’t, you can have a look at what we wrote. Just check it out from github (the actor system is less than 150 LOC !).

Rafał Sumisławski
Rafał Sumisławski
Scala tech lead, performance focused developer, home-made electronics designer and an MTB amateur

Comments are closed.