Return to site

Concurrent Programming with Akka

BEAM needs to be scalable. Our grand vision for BEAM is to simulate entire states or nations, not just individual urban regions. To get to this scale, model computations must be distributed across cores and nodes. We've therefore decided to adopt Akka as our framework for developing a simulation where code is concurrently executed to the maximum extent possible.

Akka is a library that implements the actor model of computation for the JVM. Actors are highly encapsulated objects such that all data internal to the actor is protected from concurrent access by enforcing a strict protocol of inter-actor communication through message passing. Within an agent, all computation occurs serially as actors respond to messages one at a time. But across actors, message processing occurs concurrently, so there are no guarantees about which actors will be operating at any given instant or in what order.

The key benefit of using Akka in BEAM is that do not have to micromanage threads and memory location. Instead, we design our agents according to the actor model, do some configuration of the Akka system, and the library does the rest for us. This means we spend our time spent where it matters most, reasoning about transportation and traveler behavior.

The biggest challenger to using Akka for BEAM is the balance between performance and realism. In a world of cause and effect, chronology matters very much. But we have decided to relax the constraint of strict chronology in our simulation. Instead, we maintain a window (e.g. 2 minutes) within which we no longer guarantee that actions of different agents will happen in chronological order. This allows us to get a lot of work done in parallel. But it does mean that if two agents want to use the same parking spot and our policy is first come first served, the one who wins could conceivably arrive to the spot 119 seconds after the loser with a 2 minute window.

We of course can enforce strict chronology by reducing the size of our window to 1 second. So in the coming months we will experiment with the window in order to determine the right tradeoff between realism and performance. 

All Posts

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!

OKSubscriptions powered by Strikingly