background preloader

Actor Model

Facebook Twitter

Project Orleans

Jason. Akka. Asynchronous Agents Library. The Asynchronous Agents Library (or just Agents Library) provides a programming model that lets you increase the robustness of concurrency-enabled application development. The Agents Library is a C++ template library that promotes an actor-based programming model and in-process message passing for coarse-grained dataflow and pipelining tasks. The Agents Library builds on the scheduling and resource management components of the Concurrency Runtime. The Agents Library provides alternatives to shared state by letting you connect isolated components through an asynchronous communication model that is based on dataflow instead of control flow. Dataflow refers to a programming model where computations are made when all required data is available; control flow refers to a programming model where computations are made in a predetermined order.

The Agents Library is composed of three components: asynchronous agents, asynchronous message blocks, and message-passing functions. Basic Actor Model using TPL Dataflow in C# The Actor Model is a popular way to get reliable currency into your application through isolated immutability. Microsoft does not provide an Actor class, but they do provide a part of the Task Parallel Library called Dataflow.

This is most useful for building asynchronous Pipelines but can also be used to create basic agents. Here we will see how to create a basic non transactional Actor and use that Actor to calculate primes just as in the Java Akka example. Here we simply take in the upper bound of the number range in which we want to find primes and the level of concurrency like before in our Java example. You can see we create the number of Actors we need to meet our desired concurrency level.

We add each actor to a list and we post a message to each actor. Finaly we sum the results for all actors by using LINQ. This is a very basic example to show the fundamentals of TPL Dataflow, in a real implementation we would most likely want to have less actors and have them do more work.