Comparison of Active Objects and the Actor Model Thomas Rouvinez, Candidate Msc

Comparison of Active Objects and the Actor Model Thomas Rouvinez, Candidate Msc

UNIVERSITE´ DE NEUCHATEL,ˆ INSTITUT D’INFORMATIQUE, RAPPORT DE RECHERCHE, JUNE 2014 – RR-I-AS-14-06.1 1 Comparison of Active Objects and the Actor Model Thomas Rouvinez, Candidate MSc. Computer Science , University of Freiburg, Advisor: Anita Sobe, Post Doc, University of Neuchatelˆ Abstract—This paper compares two patterns of concurrency: the Actor Model and the Active Object Model. The Actor Model is a pattern that decouples function invocation from execution and offers both inherent thread-safety and scalability. The Active Object Model inherits from the Actor Model and as such presents the same major properties. As the Active Object Model inherits from the Actor Model one may think they are equivalent. Throughout this paper we show that both patterns differ in terms of structure design and communication protocols. These differences affect the choice of pattern for specific applications as each pattern has strengths and weaknesses. Keywords—Actor Model, Active Object, Concurrency, AKKA framework. F 1 INTRODUCTION inconsistencies becomes even harder due to the non- deterministic nature of concurrent programs. To enable ULTI-CORE enabled machines hit markets in the M early 2000s. Nowadays multi-core CPUs have faster and safer developments, one solution consists largely replaced single cores. The before common se- in using inherently concurrent patterns with implicit quential programs were naturally deterministic. They synchronization mechanisms as conceptualized in the can be read top-bottom while preserving the temporal Actor Model [2]. order of instructions [1]. As a counterpart, determinism leads to bad performance on multi-core architectures. Introduced by Carl Hewitt in 1973, the Actor Model Indeed, operations are forced to execute one at a time uses message passing in combination with encapsulated and in order, regardless of any opportunities for paral- states. It is inspired by the multi-agent design of artificial lelism. The goal of concurrent programming lies in effi- intelligence. Agents are grouped into layers representing ciently using the existing multi-core resources, resulting different levels of abstraction of the problem to solve. in improved performance. In turn, exploiting parallelism Each agent belongs to one level and may spawn new requires programs to be as scalable as possible. sub-agents to handle the workload or new tasks. Actors inherit from agents and provide desirable properties A program achieves maximum scalability by ensuring like data encapsulation, fair scheduling and location that all cores of a CPU are fully loaded throughout its transparency [3]. The Actor Model inspired other execution. To reach high levels of scalability the span patterns like the Active Object Model which inherits of the code should be minimized. The span represents most of its properties. the minimum sequence of sequential operations the code should perform throughout its execution (serial In this paper, we focus on comparing the Actor Model bottleneck). The potential speedup of parallel programs and the Active Object Model. They exhibit desirable is directly limited by their sequential portion of code properties such as a high capacity to split the workload (Amdahls law). A well thought scalable program will into lightweight, independent tasks to achieve maximum automatically perform better regardless of the number and automatic scaling. We also explore the different of cores provided. guarantees regarding consistency and concurrency of Besides the performance gains parallelism can bring, both models. In our experiments, we will use the AKKA concurrent programs lead to hazards such as data races, framework as it already supports implementations of violated consistency, liveness and progress issues caused both patterns. by multiple threads accessing shared data. Imposing a strict parallel structure to a program helps avoiding such This paper is organized as follows: Section III presents hazards but limits its scalability, hence its performance. both the Actor Model and Active Object patterns. Sec- Developing concurrent applications remains a challenge tion IV explains similarities between the two patterns requiring deep knowledge of concurrency in hardware in terms of method invocation, execution and message as well as in software. Debugging deadlocks or data passing. Structural differences are also discussed. Section V provides implemented examples to highlight some • Thomas Rouvinez: [email protected] of the differences between the Actor Model and Active • Dr. Anita Sobe: [email protected] Object. Section VI addresses possibilities of mixing both UNIVERSITE´ DE NEUCHATEL,ˆ INSTITUT D’INFORMATIQUE, RAPPORT DE RECHERCHE, JUNE 2014 – RR-I-AS-14-06.1 2 patterns to achieve various combinations of desirable properties in concurrency. Finally, section VII presents the state of the art in bringing concurrency even within actors/servants. 2 PATTERNS OVERVIEW To understand the differences and similarities between the Actor Model and the Active Object Model, we first introduce their basic principles separately. 2.1 Actor Model The Actor Model (AM) is a pattern using actors as its universal primitive to perform concurrent computations [4]. Parallel computations are realized by decomposing an intent into subtasks and distributing them over Fig. 1. The structure of an actor. In response to a suitable actors. An actor may be considered as a worker message, an actor can (1) change its internal state, (2) that processes messages sent by other actors. To better send a message, (3) spawn new actors or migrate to understand how parallelism is achieved, we will present another host. the structure of actors as well as their communication protocols. an extension mechanism that may be exploited to boost An actor is an object that encapsulates both control scalability and concurrency. Note also that each part and data flow into a single object (see Figure 1). Actors of an actor could be an actor itself. For example, the feature three main components: (1) an internal state, (2) mailbox could be an actor that stores messages, or the a mailbox and (3) a set of functions to query and modify internal state a database actor. We conclude that actors the internal state. The internal state is a combination of are highly scalable and thread-safe. The AM handles the variables and objects that represent the knowledge of known concurrency difficulties for the programmers and the actor. This data are encapsulated within the actor provides guarantees, which we discuss in section 2.3. and only the actor itself may access it. Actors only have influence on the state of another actor by sending 2.2 Active Objects messages. The Active Objects Model (AOM) is another pattern Sending a message is an asynchronous, non-blocking for concurrency largely inspired by the AM. An active operation for the sender. Messages use arbitrary commu- object features private data and methods like any nication topologies [5] and can contain any type of object. passive object (common object). The difference is that An actor can only interact with another actor if it knows an active object runs in its own thread of control. its address. Security is achieved through the scope of There is not a single way to implement the AOM. addresses an actor is allowed to send messages to. Upon However, most commonly the goal is to decouple reception of a new message, the actor enqueues it into method invocation from execution to simplify object its respective mailbox. Messages are then dequeued one access [6]. This property enables the client to continue at a time for processing. its work while waiting for an answer. Furthermore, it To process the messages, each actor comprises a set of is not possible that two method calls of one particular functions. Actors can be described as Turing machines active object run at the same time [7][6]. This condition that are programmed to react according to a specific guarantees that the implementation of an active object input. The actor progresses as it dequeues messages from does not require additional thread-safety mechanisms the mailbox and matches their type to the corresponding [7]. block of statements to execute. When the processing of the current message is finished, the actor will dequeue To better understand how decoupled method invoca- the next message from the mailbox as long as it still tion and execution work in active objects, let us review contains messages. the components of the model as shown in Figure 2. The Actors have a defined life cycle: Once spawned, they first essential notion is that the client and the active object are started and wait until they receive messages. When queried run in separate address spaces and threads. We an actor is not used anymore, another actor may send a distinguish the client space from the active object space. signal to destroy it. Each actor may spawn new actors, In figure 2 the limit between the two spaces is shown by which is done for similar reasons as recursive functions the vertical bar below the proxy. call themselves, i.e to reduce the problem until it becomes In the client space we find the client and the proxy. The small enough to be processed. Spawning new actors is proxy is an interface object between the client space and UNIVERSITE´ DE NEUCHATEL,ˆ INSTITUT D’INFORMATIQUE, RAPPORT DE RECHERCHE, JUNE 2014 – RR-I-AS-14-06.1 3 Fig. 3. Workflow of a request with an active object [6]. manages the activation queue, but also selects which method request is eligible for dequeuing and execution. This selection is based on multiple criteria like ordering Fig. 2. Architecture of an active object [6]. of method requests and synchronization constraints. To ensure all synchronization constraints are met before de- queuing and executing a method request, the scheduler the active object space. The client can call a function in uses guards. the same way as calling a function on passive objects. The proxy takes care of translating the function call and Guards check for execution order, potential writing its parameters into a method request and forwards it to operation hazards and the current state of the active the scheduler for asynchronous execution.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us