An Actor-Based Software Framework for Developing and Simulating Complex Systems Agostino Poggi Dipartimento di Ingegneria dell’Informazione Università degli Studi di Parma Parma, Italy agostino.poggi@unipr.it Abstract —ASiDE is an actor-based software framework that has libraries and languages had to choose between to make simple the goals of simplifying the development of large and distributed the writing of the code (by using the thread based programming complex systems and of guarantying an efficient execution of model) and to allow the development of efficient large systems applications. This software framework provides a flexible actor (by using the event based programming model). implementation that simplifies the writing of the actors by delegating the management of events (i.e., the reception of Simulation models are increasingly being used to solve messages) to the execution environment, and allowing the choice problems and to aid in decision-making. The size and between an active thread solution (i.e., each actor has its own complexity of systems which are usually modeled (e.g., thread) and a passive thread solution (i.e., several actors share communication networks, biological systems, weather the same thread). In particular, the second thread solution is forecasting, manufacturing systems, etc.) is ever increasing. suitable to implement systems whose behavior should be modeled Modeling and simulation of such systems is challenging in that through the use of a large number of actors. ASiDE is currently it requires suitable and efficient simulation tools that take used for proving its advantages for the development of agent advantage of the power of current computing architectures and, based modeling and simulation tools. of course, of programming languages and software frameworks that can exploit such kinds of architecture and that offer the Keywords - Actor model, software framework, concurrent features useful for the development of such kinds of system. In programming, distributed systems, ABMS. particular, agent-based modeling and simulation (ABMS) tools and techniques seem be the most suitable means to exploit the I. INTRODUCTION power of such computing architectures [13][19]. Computing architectures are getting increasingly This paper presents an actor based software framework, distributed, from multiple cores in one processor and multiple called ASiDE (Actor based Simulation and Development processors in a computing node, to many computing nodes. It Environment), that has the features for simplifying the demands a bigger need for distributed and concurrent development of large and distributed complex systems and for programming because sequential programming models are not guarantying an efficient execution of applications. The next suitable to such kinds of architectures. section introduces related work. Section three describes the Distributed and concurrent programming is hard and is not software models that are the basis of the framework. Section like that of sequential programming. Programmers have more four describes the features of its current implementation. concerns when it comes to taming parallelism. Distributed and Section five introduces its initial experimentation for agent concurrent programs are usually bigger than equivalent based modeling and simulation. Finally, section six concludes sequential ones. Models of distributed and concurrent the paper by discussing its main features and the directions for programming languages are different from familiar and popular future work. sequential languages [11][18]. Message passing models seems be the more appropriate II. RELATED WORK given that they can cope with all the problems caused from the Several actor oriented libraries and languages have been sharing of data among the concurrent parts of a system. One of proposed in last decades and a large part of them use Java as the well-known theoretical and practical models of message implementation language. A lot of work has also been done in passing is the actor model. Using such a model, programs the field of agent-based modeling and simulation. Moreover, become collections of independent active objects (actors) that some works used the actor model for the modeling and exchange messages and have no mutable shared state [1][2][9]. simulation of complex system. The rest of the section presents Actors can help developers to avoid issues such as deadlock, some of the most interesting works presented in the previous live-lock and starvation, which are common problems for three fields. shared memory based approaches. There are a multitude of Salsa [22] is an actor-based language for mobile and actor oriented libraries and languages, each of which Internet computing that provides three significant mechanisms implements some variant of actor semantics. However, such based on actor model: token-passing continuations, join continuations, and first-class continuations. In Salsa each actor actor has its own thread, and so scalability is limited. Moreover, message passing performance suffers from the overhead of reflective method calls. Kilim [21] is a framework used to create robust and massively concurrent actor systems in Java. It takes advantage of code annotations and of a byte-code post-processor to simplify the writing of the code. However, it provides only a very simplified implementation of an actor model where each connections actor (called task in Kilim) has a mailbox and a method actor space defining its behavior. Moreover, it does not provide remote messaging capabilities. Scala [7] is an object-oriented and functional programming language that provides an implementation of the actor model unifying thread based and event based programming models. In fact, in Scala an actor can suspend with a full thread stack (receive) or it can suspend with just a continuation closure (react). Therefore, scalability can be obtained by sacrificing code writing simplicity. In particular, Scala has been used for the development of Scalation [14]. Scalation is a domain specific language which supports multi-paradigm simulation Figure 1. ASiDE system architecture. modeling, including dynamics, activity, event, process and state oriented models. computing techniques to efficiently distribute agents across a distributed network of computers. This software infrastructure Jetlang [20] provides a high performance Java threading uses several optimizing techniques to address three library that should be used for message based concurrency. The fundamental problems related to agent communication between library is designed specifically for high performance in- nodes: agent distribution, service agent discovery and message memory messaging and does not provide remote messaging passing for mobile agents. capabilities. An actor based infrastructure for distributing RePast Swarm is the ancestor of many of the current ABMS models [17] is proposed in [4]. This solution allows, with platforms [15]. The basic architecture of Swarm is the minimal changes, to address very large and reconfigurable simulation of collections of concurrently interacting agents, models whose computational needs (in space and time) can be and this paradigm is extended into the coding, including agent difficult to satisfy on a single machine. Novel in the approach inspector actions as part of the set of agents. So in order to is an exploitation of a lean actor infrastructure implemented in inspect one agent on the display, you must use another hidden, Java. In particular, actors bring to RePast agents migration, non-interacting agent. Swarm is a stable platform, and seems location-transparent naming, efficient communication, and a particularly suited to hierarchical models. Moreover, it supports control-centric framework. good mechanisms for structure formation through the use of multi-level feedback between agents, groups of agents, and the Statechart actors [5] are an implementation of the actor environment (all treated as agents). computational model that can be used for building a multi- agent architecture suitable for the distributed simulation of Repast is a well-established ABMS platform with many discrete event systems whose entities have a complex dynamic advanced features [17]. It started as a Java implementation of behavior. Complexity is dealt with by specifying the behavior the Swarm toolkit, but rapidly expanded to provide a very full of actors through “distilled” statecharts [8]. Distribution is featured toolkit for ABMS. Although full use of the toolkit supported by the theatre architecture [3]. This architecture requires Java programming skills, the facilities of the last allows the decomposition of a large system into sub-systems implementations allow the development of simple models with (theatres) each hosting a collection of application actors, little programming experience [16]. allocated for execution on to a physical processor. MASON is a Java ABMS tool designed to be flexible enough to be used for a wide range of simulations, but with a III. ASIDE special emphasis on “swarm” simulations of a very many (up to millions of) agents [12]. MASON is based on a fast, ASiDE (Actor based Simulation and Development orthogonal, software library to which an experienced Java Environment), is an actor based software framework that has programmer can easily add features for developing and the goals of simplifying the development of large and simulating models in specific domains. distributed complex systems and of guarantying an efficient execution of applications. This software framework provides a The Adaptive Actor Architecture [10] is an actor-based flexible actor implementation that simplifies the writing of the software infrastructure designed to support the construction of actors by allowing the choice between an active thread solution large-scale multi-agent applications by exploiting distributed (i.e., each actor has its own thread) and a passive thread solution (i.e., several actors share the same thread), and by such a timeout: its implementation will autonomously observe delegating the management of events (i.e., the reception of the firing of the timeout and then will execute the actions for its messages) to the execution environment on the basis of the management. current thread solution (i.e., actors execution is simply blocked for waiting for messages when the active thread solution is B. Actor Spaces used, actors execution is scheduled only when they receive new Depending on the complexity of the system and on the messages when the passive thread solution is used. availability of computing and communication resources, actors can be aggregated in one or more actor spaces. Figure 1 shows A. Actors a graphical representation of the architecture of an ASiDE In ASiDE a system is based on a set of interacting actors system. that perform tasks concurrently. An actor space is a concurrent object that acts as container An actor is an autonomous concurrent object which of a set of actors. In particular, an actor space supports a interacts with other actors by exchanging asynchronous transparent communication between local actors and remote messages. Communication between actors is buffered: actors (i.e., the actors of the other actor spaces) and enhances incoming messages are stored in a mailbox until the actor is their functionalities through a set of services (e.g., the ready to process them. broadcasting of messages to local actors and the migration of local actors to other actor spaces). Each actor has a unique mail address which is used to specify a target for communication. After its creation, an actor Actors can require the execution of such services by can change several times its behavior until it kills itself. Each sending a message to an actor space. Therefore, even an actor behavior has the main duty of processing a set of specific space has a unique name (address) and a mailbox. Moreover, messages. Therefore, if an unexpected message arrives, then it local actors know a priori the address of their actor space and is maintained in the actor mailbox until a next behavior will be remote actors can receive the address of the other actor spaces able to process it. of a system through some messages. An actor can perform five types of action: IV. IMPLEMENTATION - It can send messages to other actors or to itself. - It can create new actors. ASiDE is implemented by using the Java language and - It can update its local state. takes advantage of preexistent Java software libraries and - It can change its behavior. solutions for supporting concurrency and distribution. - It can kill itself. The architecture of an ASiDE application can be divided in An actor has not direct access to the local state of another an application and a runtime layer. The application layer is actor and can exchange data with another actor only when it represented by the specific actors and actor spaces of the creates a new actor or when it sends a message. However, it is application. The runtime layer implements the ASiDE its implementation that will (or will not) guarantee that actor middleware infrastructures to support the development of creation and message passing actions do not allow the sharing applications based on several actors distributed on a set of of mutable data. different actor spaces. An actor can send messages only to the actors of which it The current implementation, besides building the knows the address, that is, the actors it created and the actors of components of the runtime layer, provides some components which it received their addresses through a message. An actor (i.e., interfaces, concrete and abstract classes) to simplify the can send messages that require or not an answer and that are development of the actors of an application. replies to the messages of other actors. In particular, an actor The design of the software has been planned with the goal can perform four different actions for sending messages: of guaranteeing an easy development of several - It can send a message to another actor without requiring an implementations of the components of the runtime layer that answer. take advantages of different technologies and algorithms - It can send a message to another actor requiring an answer. without the need of modifications to the application layer (i.e., - It can reply to a message of another actor without requiring the code of the actors). This feature is important for enabling an answer. the use of different solutions for the management of the - It can reply to a message of another actor requiring an execution of the actors running inside the same actor space, but answer. also for supporting the communication among actors of different actor spaces. An actor has not explicit actions for the reception of messages, but its implementation will autonomously manage An actor is composed of two main parts: a plugger and a the reception of messages and then will execute the actions for behavior. A plugger is a component of the runtime layer that their processing. provides the main functionalities of an actor (i.e., the threading solution, the way in which it is executed and the An actor has the possibility of setting and then modifying a implementation of its actions). A behavior is a component of timeout within its current behavior must receive a message. the application layer that defines the actions that an actor will However, it has not explicit actions for managing the firing of perform during a specific part of its life. Therefore, the the behavior and for killing itself. Of course, the updating of the local state can obtained through the use of either the simple plugger behavior operators of the Java language or through the methods implementing the actor actions. mailbox state A plugger acts as interface between an actor and the input/ouput method messages calls runtime layer and provides the implementation of the actions that an actor can perform. ASiDE provides different cases configurable implementations of a plugger. Therefore, the use address of the possible different implementations and configurations of a plugger allow providing different behaviors and performances for the same application. In particular, the current plugger implementations and configurations allow: i) to Figure 2. Actor architecture have two different thread solutions (i.e., actor of an actor space either have their own thread or share a single thread), ii) to development of an application involves, besides the enable the logging of the main actor activities (e.g., the sending deployment of the actors in different actor spaces, the of messages and the processing of messages and timeouts), iii) configuration of the pluggers used in the application and the to impose the exchange of only immutable objects between development of the code of the behaviors used by the actors of actors, and iv) to use different scheduling algorithms in the the application. Figure 2 shows a graphical representation of case that actors share a single thread. the architecture of an actor. A message is an object that contains a set of fields In ASiDE, an actor is defined by extending the Actor maintaining the typical header information and a field abstract class and by implementing the methods driving its maintaining the exchanged data. TABLE 1 introduces a short behavior. In particular, this kind of implementation implies that description of the field of a message. when an actor moves from a behavior to another one, an actor object is replaced by another one. Of course, the sequence of TABLE 2 actor objects that drive the life of an actor share the same Constraint name Constraint description address and mailbox objects. To do it, ASiDE implements the All(c, O) True if all the objects of a collection creation of actors through a factory that creates a plugger satisfy the constraint (containing the address and the mailbox of the actor) and And(C, o) True if the object satisfies all the constraints passes it to the actor constructor, and implements the change of IsDifferent(o1, o2) True if the object is different from the behavior through the actor plugger that passes its reference to reference object the constructor of the next actor. IsEqual(o1, o2) True if the object is equal to the TABLE 1 reference object IsHigher(o1, o2) True if the object is greater than the Field name Field description reference object Identifier Identifier oif the message IsInstance(t, o) True if the object is an instance of the Sender Address of the sender actor reference type Receiver Address of the receiver actor IsLower(o1, o2) True if the object is less than the Content Content of the message reference object Time Delivery time of the message IsNull(o) True if the object is null NeededReply True if the message needs a reply IsOneOf(O, o) True if the object is one of the set of InReplyTo Identifier of the replied message objects Matches(p, o) True if the object matches the pattern Not(c, o) True if the object does not satisfy the The original actor model associates a behavior with the task constraint of messages processing. In ASiDE, a behavior can perform Or(C, o) True if the object satisfies at least one three kinds of tasks: an initialization task, the management of of the constraints message reception timeouts, and the processing of messages. Some(c, O) True if at least one of the objects of a Initialization is performed by the initialize method and collection satisfies the constraint timeouts management is performed by the getTimeout, setTimeout and timeout methods. In particular, the initialize As introduced above, an actor processes the received and timeout methods can be overridden for defining specific messages through a set of case objects and each of them can behaviors. process only the messages that match a specific message pattern. In ASiDE, a message pattern is an object of the The processing of messages is performed by some case MessagePattern class that can apply constraints on the value of objects. A case has the goal of processing the messages that all the fields of a message. A constraint is also an object of one match a specific (and fixed) message pattern. In ASiDE, a case of a predefined set of classes that implement the Constraint is defined by extending the ActorCase abstract class and by interface. TABLE 2 introduces a short description of the implementing its process method. The code of the methods that possible constraints. drive the behavior of an actor (i.e., initialize, timeout and process) is built on a set of methods that implement the actions This kind of representation of a message pattern allows a for sending messages, for creating other actors, for changing very sophisticate filtering of messages. Moreover, the use of The performances of an application, its behavior and the possibility of monitoring and debugging its execution depend Actor Space on its configuration. In fact, the configuration step allows the input messages choice of: - The threading solution for each actor space: active, actors mailbox Services have their own thread, or passive, actors share a single thread. - The algorithm used for scheduling the actors of each actor address space (in the case of passive threading solution). output messages - The services provided by each actor space. - The communication technology used for connecting the Figure 3. Actor space architecture actor spaces of the application. - The activities of the actor and actor spaces that must be the Matches constraint allows a specialization of the filtering logged. for all the message fields and in particular for the content of the message. The current implementation of ASiDE provides an The choice that mainly determinates the performances of an additional pattern, implemented by the RegularExpression application is the threading solution. In fact, while with the class. This pattern allows the filtering of the messages by active threading solution each actor of an actor space is matching the string representation of the value of a field with a executed in a distinct Java thread, with the passive thread specific regular expression. solution all the actors of an actor space share a single Java thread and their execution is managed through a scheduler. The New types of pattern and constraint can be added. Of choice of the threading solution may influence the behavior of course, it requires working at the application and runtime the application. In fact, using the active threading solution, layers. At the application layer, it is necessary to develop the different executions of the application can have different classes representing such patterns and/or constraints. At the behaviors because of the different arrival order of messages (of runtime layer, it is necessary to develop the software course, if the application is started with the same initialization components able to uses such patterns and/or constraints for information). Using the passive threading solution, the simplest filtering messages. scheduling algorithms guarantee the same arrival order of An actor space is a component of the runtime layer that, as messages for different execution of the application. introduced, above, has the duty of both supporting the communication between local actors and remote actors and to V. USING ASIDE FOR ABMS provides them a set of services. Figure 3 shows a graphical The features of the actor model and the flexibility of its representation of the architecture of an actor space. implementation make ASiDE suitable for building agent based The implementation of the actor space allows the modeling and simulation tools. In fact, the use of passive actors deployment of a system with different communication allows the development of applications involving large number technologies and with different set of services. However, while of actors, and the possibility of using different schedulers for all the actor spaces of a system need to use the same their execution allows the development of schedulers that are communication technology; anyone of them can provide a specialized for some specific application domains. different set of the services. In fact, services are divided in The first experimentation of ASiDE for modeling and mandatory and optional, and an actor space must provide all simulating systems has been dedicated to the well-known game the mandatory services and can choose what of the others to of life [6]. The model of such a game is based on a grid of provide. New kinds of service can be added. Of course, it LifeCell actors that have been created by a Creator actor and requires working at the application and runtime layers. At the initialized by a set of Initializer actors that send them the application layer, it is necessary to develop the classes acquaintance (i.e., the address) of the neighbors actors The representing the service requests that actors need to send to the behavior of the LifeCell actor is very simple given that it cycles actor spaces. At the runtime layer, it is necessary to develop the on the following three tasks: software components able to perform the services. - Get messages from neighbors. The current implementation of ASiDE allows building both - Compute the new state. standalone and distributed applications and associated an actor - Send messages to neighbors. space with a Java virtual machine. A standalone application is based on a single actor space created with an initial agent that The implementation of the actor involves the will start the application execution. A distributed application is implementation of the initialize and timeout methods and the based on more than one actor space. Each actor space can have creation of a case for processing of the messages coming from an initial agent, but usually a distributed application start with a the neighbors. In particular, while the initialize method sets the set of empty actor spaces and an “initiator” actor space with an initial state of the cell, the timeout method computes the new initial actor that also starts one or more actors on the other state and then send a message to the neighbor. Finally, the actor spaces. process method of the case of the actor needs only to count the messages notifying that a neighbor is living. This experimentation gave the opportunity to make some actors of a system (e.g., group communication protocols) and measures of the performance of the ASiDE software for to enable the interoperability with Web services and legacy developing simulations involving different numbers of actors. systems. TABLE 3 presents the execution times of two simulations of the “game of life” having a length of respectively a hundred REFERENCES and a thousand of cycles and involving from few hundreds to [1] G.A. Agha, Actors: A Model of Concurrent Computation in Distributed more than a million of actors. These results were obtained on a Systems. MIT Press, Cambridge, MA, 1986. laptop with an Intel Core 2 - 2.80GHz processor, 8 GB RAM, [2] G.A. Agha, I.A. Mason, S.F. Smith, and C.L. Talcott, A Foundation for Windows 7 OS and Java 7 with 4 GB heap size. Moreover, all Actor Computation. Journal of Functional Programming, 7(1):1-69, the performed experimentations showed that the use of the 1997. passive threading solution provides better performances than [3] F.Cicirelli, A. Furfaro, and L. Nigro. “Exploiting agents for modelling the active one even with a few number of actors. and simulation of coverage control protocols in large sensor networks”. The Journal of Systems and Software, 80(11):1817-1832, 2007. TABLE 3 [4] F.Cincirelli, Distributing ResPast simulations using actors. in: Proc. of Actors number Execution time (ns) 23rd European Conference on Modelling and Simulation (ECMS’09), 9– 100 cycles 1000 cycles 12 June, Madrid, 2009, pp. 226–231. 256 176.943.577 260.195.988 [5] F. Cincirelli, A. Furfaro and L. Nigro. Modeling and Simulation of 1.024 233.455.065 419.241.045 Complex Manufacturing Systems using Statechart-based Actors. 4.096 605.946.575 1.995.799.263 Simulation Modelling Practice and Theory, Volume 19, Issue 2, Pages 16.384 3.420.273.304 20.098.356.918 685–703, 2011. 65.536 14.203.557.943 90.057.744.911 [6] M. Gardner, The fantastic combinations of John Conway's new solitaire 262.144 57.711.405.356 372.067.196.751 game Life. Scientific American 223:120-123, 1970. 1.048.576 222.013.993.687 1.375.419.844.501 [7] P. Haller and M. Odersky, Scala Actors: Unifying thread-based and event-based programming. Theoretical Computer Science, 410(2- 3):202–220, 2009. VI. CONCLUSIONS [8] D. Harel and A. Naamad. The STATEMATE semantics of Statecharts. This paper presented a software framework, called ASiDE, ACM Trans. on Soft. Eng. And Methodology (TOSEM), 5(4): 293–333. which uses the most natural programming model for writing 1996. actors code (i.e., the thread based model), but allows also the [9] C.E. Hewitt, Viewing controll structures as patterns of passing messages. Artificial Intelligence, 8(3):323–364, 1977. development of efficient large systems by combining the [10] M. Jang, and Gul Agha, "Scalable Agent Distribution Mechanisms for sharing of threads among the actors of the systems with the Large-Scale UAV Simulations," Proc. Int. Conf. of Integration of delegation of the management of the reception of messages to Knowledge Intensive Multi-Agent Systems, Waltham, MA, 2005. the execution environment. [11] C. Leopold, Parallel and Distributed Computing: A Survey of Models, Paradigms and Approaches. John Wiley & Sons, Inc., New York, NY, ASiDE is implemented by using the Java language and its 2001. use can simplify the development of systems in heterogeneous [12] S. Luke, C. Cioffi-Revilla, L. Panait, K. Sullivan, and G. Balan, environments where computers, mobile and sensor devices MASON: A Multiagent Simulation Environment. Simulation 81, 7, must cooperate for the execution of tasks. 2005, 517-527. [13] C.M. Macal and M.J. North, Tutorial on agent-based modelling and We are using the ASiDE software framework for the simulation, Journal of Simulation (2010) 4, 151–162. development of some applications in the fields of distributed [14] J.A. Miller, J. Han, and M. Hybinette, “Using Domain Specific information sharing, social networks and ABMS. A first Language for Modeling and Simulation: ScalaTion as a Case Study," In analysis of the experimentation shows that each computing Proc. of the 2010 Winter Simulation Conference, pp.741-752, 2010. node (actor space) can efficiently run more than a million of [15] N. Minar, R. Burckhart, C. Langton, and V. Askenasi, The Swarm actors and the work of a system can be distributed on several Simulation System: a Toolkit for Building Multi-Agent Systems. 1996. computational nodes with a limited overhead in a local Available from http://www.swarm.org/ network. [16] M. J. North, T. R. Howe, N. T. Collier, and J. R. Vos. The repast simphony runtime system. In Proceedings of the Agent 2005 Conference Future research activities will be dedicated, besides to on Generative Social Processes, Models, and Mechanisms, 2005. continue the experimentation and validation of the software [17] M. North, N. Collier, and J. Vos. Experiences in creating three framework in the distributed information sharing and for using implementations of the repast agent modeling toolkit, ACM ABMS in the field of social networks modeling and analysis, Transactions on Modeling and Computer Simulation, 16(1):1-25. 2006. and to the improvement and the extension of the software [18] M. Philippsen, A survey of concurrent object-oriented languages. Concurrency: Practice and Experience, 12(10):917-980, 2000. framework. In particular, current activities are dedicated to: i) [19] S.F. Railsback, S.L. Lytinen, and S.K. Jackson. Agent-based simulation allow the mobility of actors between different actor spaces, ii) platforms: Review and development recommendations. Simulation, provide a passive threading solution that fully take advantage 82(9):609–623, 2006. of the feature of multi-core processors, iii) to define a set of [20] M. Rettig, Jetlang software Web site. Available from actors schedulers and supporting tools for performing http://code.google.com/p/jetlang/. simulations and the analysis of the results of the simulations in [21] S. Srinivasan and A. Mycroft, Kilim: Isolation-Typed Actors for Java. In some specific application domains, iv) to improve the J. Vitek ed. ECOOP 2008 – Object-Oriented Programming, LNCS, scalability of simulations on the number of actors through the 5142, pp. 104-128, Springer, Berlin ,Germany, 2008. definition of distributed actors schedulers, and v) provide a set [22] C. Varela and G.A. Agha, Programming dynamically reconfigurable of actor space services to simplify the coordination among the open systems with SALSA. SIGPLAN Notices, 36(12):20-34, 2001.