Actors in A New "Highly Parallel" World

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Actors in a New “Highly Parallel” World

Fábio Corrêa
Polelo Research Lab
University of Pretoria
Pretoria, 0002
+27-12-420-3617
feamcor@gmail.com

ABSTRACT
The actor-model of computation was forged 25 years ago and,
despite its natural fitness for concurrent programming, it never got 1. INTRODUCTION
traction on mainstream programming languages and as a
widespread programming technique, it has been restricted mainly 1.1 A Law in Danger of Extinction
to academic experiments. The functional programming paradigm, A few years ago the processor industry noticed that the continuity
available since the inception of the first high-level programming of Moore’s Law was under serious threat. The traditional
languages, despite the success of some of its languages, mostly on approach to CPU performance improvement, through the addition
the academic environment, and its natural ability to avoid the of more transistors per chip (density), and the increase of clock
inherent problems of concurrency, also never got traction on speed, had hit some (physical) walls: excessive power
commercial development, being overshadowed by the consumption and thermal dissipation. It was no longer possible to
proliferation of imperative languages. Recently, Moore’s Law keep producing single-threaded processors in the same way as
reached a limit and, as an alternative way of evolving processors, they had been for decades, i.e. executing more instructions per
multi-core ones were developed, turning parallel systems into cycle. A new engineering approach had to be adopted in hardware
commodity. This paper presents the guidelines of research that is development and, in the meantime, in the software arena, it was
being conducted in response to the actual software engineering proclaimed that the free (performance) lunch was over [10].
crisis, on how to effectively exploit this new highly parallel world
of multi-core processors on computers and other devices. In
1.2 Two Heads are Better than One
search of an effective and efficient concurrent programming Enter the multi-core processors (a.k.a. chip multiprocessors). In
model, currently available actor-model implementations will be simple terms, the processor industry, making use of the amazing
scrutinized in order to evaluate their strengths and weaknesses density capability available these days, started to put two (or
against the omnipresent shared-state, multi-threaded model of more), under-clocked processors within the same die, sharing a
concurrent programming. single memory source, like a typical SMP configuration. These
under-clocked processors (a.k.a. cores) required less power and
consequently dissipated less heat. But, for instance, two cores
Categories and Subject Descriptors don’t mean double of performance. According to Sutter [10]:
D.1.3 [Programming Techniques]: Concurrent Programming –
“First, there is coordination overhead between the cores to ensure
Parallel Programming.
cache coherency (a consistent view of cache, and of main
D.3.3 [Programming Languages]: Language Constructs and memory) and to perform handshaking. (…) Second, unless the two
Features – Concurrent Programming Structures. cores are running different processes, or different threads of a
single process that are well-written to run independently and
General Terms almost never wait for each other, they won’t be well utilized.”
Performance, Experimentation, Languages. His second point gives a clear indication that the concurrent
software MUST be well written in order to have efficient
Keywords utilization of the processor. This statement takes us to where the
burden really lies on this new context: in the software.
Multi-core, Concurrency, Parallelism, Actors, Actor-Model,
Asynchronous Programming, Functional Programming, Erlang, 1.3 Software for a Truly Parallel World
Scala, Java, C#, F#, .NET, JVM, Kilim. Sutter’s statement that [10] “concurrency is the next major
revolution in how we write software” seems pertinent. It is the
actual hot topic in software development and, definitively, not an
easy task to handle. Concurrency was “ignored” by most
developers for years, being restricted to a few application domains
and their small group of hard-core developers. But it cannot be
ignored anymore and developers will have to adapt, in order to
absorb the outcome of the effort that is being expended by both
academic and industry researchers, in order to make this transition
as smooth as possible.

21
Non-determinism, for instance, makes the debugging of 1.5 The Functional Insurgence
concurrent software much more difficult than the debugging of Let me digress a little before moving to the actor-model, in order
essentially sequential software. Threads, synchronization, locks, to contextualize the actual insurgence of functional programming
race condition, deadlocks, live locks, thread-safe components, languages and its impact on the current concurrency crisis.
thread-pools, scalability, load balancing and shared-state, for
instance, are well-known issues, and sources of headache, for High-order functions, anonymous functions (closures), efficient
those who adventure on suck tasks. tail recursion, pattern matching, list comprehensions, shared-
nothing memory model (through immutable types and structures),
By being so difficult to master, the quest for finding a concurrent and a high-level programming style (through aggregation), that
programming model and high-level abstractions, that would be, besides being considered exotic for those not used to them, are
not only adopted by most of developers and hobbyists, but also typical features of functional programming languages that are
effective on making efficient use of the available computational becoming more and more widespread these days and these are
resources (in this case, the cores), in a dynamic fashion, is the beneficial and a good fit for concurrent programming.
main force that drives this research.
The increased popularity of such a paradigm is perceived from a
1.4 In Search of a Programming Model few scenarios:
Van Roy [12] considers that the issue of programming multi-core 1. Existing languages that were hidden in academic silos
processors is technically solved through dataflow programming; and that are currently facing a rise on popularity among
and that its adoption is actually a sociological issue. As you will development projects, e.g. Lisp and Haskell;
be able to verify in the following sections, dataflow programming
and the actor-model share many common characteristics, if they 2. Existing languages that were hidden in niche silos and
do not actually overlap each other. that are currently facing a rise on popularity among
development projects, e.g. Erlang;
It seems that the sociological issue, in this regard, is the lack of
knowledge about the options available (which would take us to a 3. New languages that were developed to run on top of
separate discussion about education) and, more importantly, an market-consolidated VMs (like JVM and .NET CLR),
e.g. Clojure, Scala and F#; and
imposition of a common and restricted set of development tools,
mainly on corporative environments that are usually not open to 4. The adoption of functional features on imperative
differentiation and experimentation, but to what is common languages; e.g. C#, Python, Ruby and Java.
knowledge and easy to get in the market.
2. THE ACTOR MODEL
Java was the first language that made thread a known term among
developers that, who up to that point, were used to the term multi- 2.1 History
threaded from the context of features of an operating system. Hewitt et al [6] defined the actor-model as part of their research
Some years ago it was very fashionable to sell the idea that one on artificial intelligence for the PLANNER-like family of AI
operating system was preemptive and multi-threaded, even if most languages. Following their seminal paper [6], other works helped
people didn’t know the exact implications of that. to define the semantics of the actor-model [15] and culminated on
Anyway, the predominant programming model for concurrency Agha [1] setting the actor-model theory in 1985. His first thoughts
today is through the use of threads on a shared-state model. Lee in the preface of his thesis [1] (“It is generally believed that the
[7] states that “threads discard the most essential and appealing next generation of computers will involve massively parallel
properties of sequential computation: understandability, architectures.”) took twenty years to start to become reality. Agha
predictability and determinism” and indicates that improving such is one of the most important and prolific researchers on the actor-
model is not the way to go as it pushes the developer to fight model and his theory is used as baseline taking in consideration
against the non-determinism of such model. As a consequence of that Hewitt et al [6] are slightly obscure, and of difficult
such thoughts, deterministic concurrency is a must on this new interpretation.
highly parallel world; otherwise, with the continuing increase of
complexity of new applications, it will be a burden too heavy for
2.2 Characteristics
developers to carry. Actors are reactive entities that have a unique name (mail address)
and, based on an incoming message received through its
Sutter and Larus [11] share the same concerns and add that individual inbox, that can [1]:
shared-state is a major constraint and that synchronization
1. Send a finite set of messages to other known actors;
methods, like locks, by not being composable and by being global
properties of an application (and not of individual components), 2. Create a finite set of new actors; and
are an overhead that has to be overcome. Lock-free programming 3. Define how it will behave in relation to the next
and transactional memory are suggested as alternatives to such incoming messages.
problem, but I consider them incipient technologies, despite, for
instance, the extensive research that is being conducted on The communication between actors in an actor system is, like in
software transactional memory (STM). dataflow [13], asynchronous, i.e. the destination actor doesn’t
have to be ready in order to the sender to send it a message.
Other concurrency abstractions like Futures [14] and Phasers [8]
are available in real and/or experimental programming languages. Actor systems are classified as message-passing systems, taking
Also, various other methods and tools, like specialized languages into consideration that all communication between actors happens
such as Fortress and X10, are not being considered and analyzed exclusively through the exchange of messages.
here by not being in the context of actors. Due to their message-passing mechanism, actors don’t share state
[4]. This means, they are not subject to memory corruption as the

22
one existent on shared-state systems, which require the explicit Erlang is today the de facto implementation of an actor-model and
use of synchronization devices, like locks, in order to avoid such it is used as reference for many of the newest actor-model
corruption. On one side, it eliminates the need for synchronization implementations. Due to its extreme scalability, it is also used as
of state (value). On the other side, the cost of copying such state baseline for benchmarks of other implementations. You can
(value) from one actor to another requires optimized and efficient consider an actor-model implementation good if it concurrently
ways of doing it, without excessively demanding intensive scales at the same level, or even more, than what you would get
memory allocation and operations, like copy. from Erlang.
In order to identify and model an actor system, and its dynamics, Erlang runs on top of its own VM, which is considered the great
the following, pretty much like the modeling of an object-oriented differentiator compared to other famous VMs like the JVM and
system, must be determined [4]: the .NET CLR. Its implementation of (light) processes is totally
1. All type of actors of the system (like classes); detached from OS threads and fully implemented and controlled
by the VM.
2. The contract that each actor responds to, i.e. which
messages it should receive (like interfaces); and 3.2 Scala
3. The behavior that each actor should take when receiving Scala [19] is a hybrid object-oriented plus functional
a message (like methods). programming language, inspired by Java but with characteristics
of many others, which compiles to Java bytecodes and runs on top
Many actor languages were developed along the years, most of of the JVM. Due to its intimate relation with Java, you can freely
them restricted to academic departments. A not so extensive list mix both, allowing you to take advantage of the extensive set of
can be found at [15], being SALSA the most prominent one. libraries and frameworks available for Java. Scala allows you to
In order to conduct the experiments of this research, I decided to use the concurrent abstractions available in Java, e.g. threads, but
evaluate only a few real world implementations of the actor- its most famous one is the Actors library that mimics the Erlang
model. implementation.
Haller and Odersky [5] describe the pitfalls encountered during
3. IMPLEMENTATIONS the development of the Actors library and the impedance between
On most of the technologies below you won’t find an explicit
the JVM and the requirements of an actor-model implementation.
reference to the actor-model or to actors themselves. You will find
Actually they mixed threads and events in a way that overcame
a mix of terms that can be confusing and deceiving most of the
these limitations and provided a performance level and scalability
time. How much of the theory of the actor-model does an
similar to those achieved by Erlang.
implementation implement is also not in question here. More or
less, all of them implement a minimum set of characteristics that Scala is released as open source. Actually there are a couple of
identify and behave like an actor system. Differences in books available about it. Some people consider Scala as the new
terminology will be described during the demonstration of the Java (a little bit of a hype in my opinion).
results of the experiments. All of the implementations listed below
can make efficient use of the cores available during runtime, 3.3 Kilim
avoiding any static setup and/or annoying re-compilations. Kilim [17] is a framework used to create robust and massively
concurrent actor systems in Java, which claims to be, at least, 3x
3.1 Erlang faster than Erlang.
Erlang [16] is a dynamically typed functional language that was Kilim makes use of a bytecode post-processor called Weaver [9]
developed at the Ericsson Computer Science Laboratory with the and a run-time library. Weaver ensures that, through annotations
purpose of being a “better way of programming telephony on the bytecode:
applications” [3]. It started in 1985 and was restricted to Ericsson
until 1997, when it was released as open source. It was developed 1. Threads will be ultra-lightweight (like fibers);
with, soft real-time, concurrency, fault-tolerance, distribution and 2. Messages will be treated as a special, and much simpler,
hot-replacement in mind, due to the very nature of the telephony category of Java objects; and
environment. Erlang is experiencing a tremendous increase in 3. Isolation is enforced on compile-time.
popularity and adoption among developers worldwide.
Armstrong, one of its original developers and still the most Besides the bytecode post-processor, the use of Kilim doesn’t
famous face on Erlang, released a book in 2007 [2], assisting in require any change to the Java language or the JVM itself.
spreading more inner details about the language. An ACM Kilim is released as open source and is still a work-in-progress.
conference, and a few other commercial conferences, happens
every year. Today, dozens of open source projects are being 3.4 Microsoft CCR/DSS Toolkit
developed using Erlang as the primary language, e.g. ejabberd, The Microsoft CCR (Concurrency and Coordination Runtime)
yaws, RabbitMQ, and CouchDB. Erlang has been shown to be a and DSS (Decentralized Software Services) Toolkit [18] is the
perfect match for server applications due to its OTP framework, new kid in town in the list of actor-model implementations.
which provides the infrastructure for the creation of resilient Originally incubated inside the Microsoft Robotics Developer
distributed applications. Studio (due to the inherent concurrency requirements when
The only concurrent programming model available in Erlang is dealing with robots) it became an official Microsoft product by
the actor-model (or Concurrency Oriented Programming, as the end of October 2008 (during the PDC 2008).
prefers Armstrong). Erlang has immutable types, pattern matching It comprises of “a set of .NET and .NET Compact Framework
and other features from a pure functional language and most of its class libraries and tools that enable developers to better deal with
design inspiration came from PROLOG.

23
the inherent complexities in creating loosely-coupled concurrent 7. REFERENCES
and distributed applications” [18]. [1] Agha, Gul. Actors: A Model of Concurrent Computation in
There is practically no scientific research published yet about Distributed Systems. MIT Artificial Intelligence Laboratory,
CCR/DSS, but it promises to be a very important contender. Ann Arbor, MI (1985)
[2] Armstrong, Joe. Programming Erlang: Software for a
4. EXPERIMENTS Concurrent World. Pragmatic Bookshelf (2007) 1st Edition
The experiments will consist of the definition of a list of software
engineering features, as well as benchmarking requests that will [3] Armstrong, Joe. A History of Erlang. Proceedings of the 3rd
be evaluated against the actor-model implementations listed in the ACM SIGPLAN conference on History of Programming
previous section and one threaded shared-state implementation. Languages - HOPL (2007)
Erlang will be considered the baseline for all the benchmarks. The [4] Ayres, John. Implementing Stage: the Actor based language.
benchmarks will not only measure performance and scalability, Final Report. Imperial College London (2007)
but also the efficiency of the underlying runtime in make effective [5] Haller, Philipp and Odersky, Martin. Actors that Unify
use of the cores available on the testing workstation. Threads and Events. International Conference on
The testing workstation is a PC with the following configuration: Coordination Models and Languages, LNCS (2007) pp. 171-
190
• 2x Intel Xeon 2.0GHz Quad Core Processors
[6] Hewitt, Carl and Bishop, Peter and Steiger, Richard. A
• 8x 2GB RAM Modules 667MHz FB-DIMM
Universal Modular ACTOR Formalism for Artificial
• 4x 500GB HDs Seagate SATA 7200RPM Intelligence. International Joint Conferences on Artificial
• 1x GeForce 9800GTX+ GPU with 512MB of VRAM Intelligence - IJCAI (1973) pp. 235-245

• OS Windows HPC Server 2008, XP and Vista 64bit [7] Lee, Edward. The Problem with Threads. COMPUTER
(2006) pp. 33-42
Distributed characteristics of the actor-model are out-of-the scope
of this research. [8] Shirako et al. Phasers: a unified deadlock-free construct for
collective and point-to-point synchronization. ICS '08:
Object-orientation will be considered as the baseline for all the Proceedings of the 22nd annual international conference on
software engineering features to be measured. Supercomputing (2008)
A set of testing applications will be developed on all the [9] Srinivasan, Sriram and Mycroft, Alan. Kilim: Isolation typed
implementations listed on the previous section. The programming actors for Java. Proceedings of the European Conference on
languages that will be used for the experiments are: Erlang, Scala, Object Oriented Programming - ECOOP (2008) pp. 104-128
Java, C# and F#. The CCR/DSS toolkit will be tested on two
different languages, namely C# an example of an imperative [10] Sutter, Herb. The free lunch is over: A fundamental turn
shared-state language and F# an example of a functional language. toward concurrency in software. Dr. Dobb’s Journal (2005)
In case any third-party component, e.g. a database, is required on [11] Sutter, Herb and Larus, James. Software and the concurrency
a test application, such component has to provide a unique and revolution. Queue (2005) vol. 3 (7) pp. 54-62
open method of interoperation for all the languages listed above.
[12] Van Roy, Peter. The Challenges and Opportunities of
5. CONCLUSIONS Multiple Processors: Why Multi-Core Processors are Easy
and Internet is Hard. (2008)
The aim of this research is to demonstrate that the actor-model is
an effective and efficient programming model for tackling the [13] Van Roy, Peter and Haridi, Seif. Concepts, Techniques and
current concurrent crisis. It also intends to describe the differences Models of Computer Programming. MIT Press (2004)
found between the implementations, in order to drive to a single section 4.9
terminology and set of abstractions, that would be part of future [14] http://en.wikipedia.org/wiki/Future_(programming) as of 30
actor-model implementations, speeding-up their adoption by November 2008
developers due to a common idiom. And last, but not least, it will
describe the effort that would be required from developers to shift [15] http://en.wikipedia.org/wiki/Actors_(concurrency) as of 30
to this paradigm. November 2008
[16] http://www.erlang.org as of 30 November 2008
6. ACKNOWLEDGMENTS
[17] http://www.malhar.net/sriram/kilim as of 30 November 2008
Thanks to Prof. Judith Bishop on giving me the opportunity to
pursue my masters and also for providing me with guidance and [18] http://www.microsoft.com/ccrdss as of 30 November 2008
resources for this endeavor. [19] http://www.scala-lang.org as of 30 November 2008

24

You might also like