Merry Christmas – or let it snow with Akka

I just played with Akka the other day, in order to get proficient to some of the basic patterns and idioms which come with the underlying Actor model.  I chose Conway’s Game of Life as a little pet project.  But instead of calculating the state of each cell by using a discrete computation model (that is calculating the state of the next generation for all cells by the fixed state of the cells current generation – then switch to the next generation, and so on)  i did it in a rather asynchronous way.

Each cell is represented as an Actor which only knows its local (surrounding) neighbours, sending asynchronous messages to each other if their state has changed (e.g. going from state ‘Dead’ to ‘Alive’). Using Akka, you really get a powerful model for handling parallel processing, yet easy to use (i can only recommend to read the very good documentation here).

Although i didn’t found any interesting cell patterns yet (like gliders, spaceships or pulsars) which may be a consequence of the asynchronous and hence somewhat random form of message propagation and processing (they rather behave like a real cell culture which is going to grow over time), i played with some of the parameters – like the conditions under which a cell is going to die or become reborn or limiting the propagation of a state change only to those neighbours which are located ‘below’ the propagating cell.

In doing so and due to the fact that Christmas is near, i adapted the behaviour of a cell culture to act accordingly to the current climatical situation – so it’s no longer a real ‘Game of Life’ but rather a ‘Let it snow – let it snow – let it snow’ …

Well, it’s not really a snow simulation, but a very generous way of keeping cells alive (and even bringing more and more cells into life within a very short period of time). Ok, lets be complaisant and say that it vaguely looks like heavy snowing.

At least, Akkas underlying technical architecture is impressive. In the example at hand i used 1800 parallel Actors, each representing a single cell (as the matrix features a dimension of 30 rows with 60 columns each).  In addition to that, there were another 1800 Actors, each one responsible for displaying (like acting as a presenter) the state of a certain cell (like representing the model). As you may have seen, the simulation is really fast (its more like a Blizzard than simple snowing, if you will). In fact the presentation technology (Scala Swing) was the limiting factor in that case.

All in all it was fun to play with Akka. And it won’t be the last time for sure! If you would like to let it snow by yourself, you’ll find the sources here at GitHub.

In this spirit – let it snow, merry Christmas and a happy new year to all of you !!!

Posted in general. 1 Comment »

One Response to “Merry Christmas – or let it snow with Akka”

  1. Merry Christmas – or let it snow with Akka Says:

    […] Conway’s Game of Life as a little pet project. But instead of calculating the state of… [full post] Mario Gleichmann brain driven development general 0 0 0 0 […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: