Message Passing Concept. Agents and actors
This article begins a series of publications on the technologies that we use and study to develop the HostTracker website monitoring service . We hope our experience will be useful.
Message passing is one of the popular concepts of parallel programming. It is often used to create complex distributed systems with a high degree of parallelism. The implementation of this concept is presented in programming languages as actors (agents) or agents (agents).

HostTracker Distributed Agents. Quick check with http://updownchecker.com
• The solution consists of isolated components that work in parallel (in parallel threads from a thread pool). The interaction between the components is through messaging over a specific protocol. Network components can use TCP, UDP, HTTP, etc. Local interact through a protocol defined by a particular language of its implementation or library.
• The component defines the logic for processing input messages. The latter fall into the queue and are sequentially taken out of it for processing.
• A component may own some resources and be their provider for other components. A resource can be: data in a specific format in RAM, a hardware-software resource, or a combination thereof.
• The component has a certain state that can encapsulate a resource (from the previous paragraph), or, as in the case of a state machine, can be expressed as a certain message processing algorithm that transfers it to another state.
• Interface between components:
- postSync, postAsync - send a message to a component synchronously or asynchronously.
- receiveSync, receiveAsync - receive a message from a component synchronously or asynchronously. Asynchronous waiting is that the stream as a resource is returned to the system and can be used for other work. In this case, the system registers a callback function for a specific event.
- tryReceive functions - similar to the above, but having a certain delay for receiving data.
• The concept is closely related to the concept of asynchronous execution.
Asynchronous execution means that the thread does not expect the result of the execution of a certain operation, using the resources of the operating system. Instead, the thread returns to the pool and can be used for other operations. In this case, a callback function is registered in the OS, which receives the result of an asynchronous operation. This function is launched upon receipt of the result (on Windows through the IO Completion ports mechanism, on Nix systems through other kernel mechanisms).
Different programming languages support this concept differently. So, JavaScript (NodeJs platform) is an example of an Event-Driven language (a language that has built-in support for working with asynchronous computing). A typical NodeJs program is the declarative registration of callback functions to IO event responses. At the beginning of its execution, a queue of operations is created in which callback functions are triggered. That is, the program itself is single-threaded, but asynchronous. That is, the program itself is single-threaded, but asynchronous. In this case, the NodeJs virtual machine (based on Chrome v8 JavaScript runtime) is an example of a message passing implementation and satisfies all of the above conditions if it implements a certain network interface for interacting with other components of a distributed application (for example, a REST service).
In some languages (for example, F # - async monad, C # - async, await) there is the concept of asynchronous computation - part of the code defined by the developer, which contains both synchronous and asynchronous operations. Also, it is possible to start calculations in a parallel stream, cancel calculations, make synchronous start.
The concept of message passing was first introduced in the Erlang language (functional language with dynamic typing), which was developed by Ericson for specialized telecommunication equipment. Erlang processes are the components described earlier. Their creation and data exchange between them, unlike OS processes, does not require a significant temporary resource. Modern functional languages such as Scala (Java platform) and F # (.NET platform) took message passing implementation from Erlang. Scala agents can exist both within the same OS process and in different processes on different computers. The principles of working with them are similar to the principles of Erlang processes. F # offers a slightly different approach - MailboxProcessor. You can also find your own message passing implementation features in the TPL Dataflow library,
Networking is built on the principles of message passing. Here, the component is a program on a separate machine, the resources are all the hardware components of the computer + individual functions that are delegated to this computing node. Data is stored in the application process memory. The interface of interaction with other components (nodes) is determined by the specific technology, usually created on Berkley sockets. As an example of such a technology, we can cite MPI (Message passing interface). Its feature is that each node processes the same code, choosing a separate branch for processing using conditional statements using a stream identifier. Zero flow is dedicated. Network communication takes place via an interface similar to the above, (message passing concept) and uses flow identifiers to indicate the source and / or receiver of melons. Another example is the REST and SOAP services, which enable the developer to determine the network interface themselves. Although, at first glance, it seems that a certain interface does not fit into the concept of message passing in this way, it is equivalent to a set of post (send) and receive operations. So, in SOAP, a network function is called by accessing the xml envelope (envelope), which includes information about the function. Functions in REST work similarly - HTTP requests are used with a data format defined by the developer. that in this way a certain interface does not fit into the concept of message passing, it is equivalent to a set of post (send) and receive operations. So, in SOAP, a network function is called by accessing the xml envelope (envelope), which includes information about the function. Functions in REST work similarly - HTTP requests are used with a data format defined by the developer. that in this way a certain interface does not fit into the concept of message passing, it is equivalent to a set of post (send) and receive operations. So, in SOAP, a network function is called by accessing the xml envelope (envelope), which includes information about the function. Functions in REST work similarly - HTTP requests are used with a data format defined by the developer.
In further publications, MailboxProcessor F # (actively used in the HostTracker system ) and the features of working with the TPL DataFlow library will be examined in detail .
Message passing is one of the popular concepts of parallel programming. It is often used to create complex distributed systems with a high degree of parallelism. The implementation of this concept is presented in programming languages as actors (agents) or agents (agents).

HostTracker Distributed Agents. Quick check with http://updownchecker.com
Features of message passing:
• The solution consists of isolated components that work in parallel (in parallel threads from a thread pool). The interaction between the components is through messaging over a specific protocol. Network components can use TCP, UDP, HTTP, etc. Local interact through a protocol defined by a particular language of its implementation or library.
• The component defines the logic for processing input messages. The latter fall into the queue and are sequentially taken out of it for processing.
• A component may own some resources and be their provider for other components. A resource can be: data in a specific format in RAM, a hardware-software resource, or a combination thereof.
• The component has a certain state that can encapsulate a resource (from the previous paragraph), or, as in the case of a state machine, can be expressed as a certain message processing algorithm that transfers it to another state.
• Interface between components:
- postSync, postAsync - send a message to a component synchronously or asynchronously.
- receiveSync, receiveAsync - receive a message from a component synchronously or asynchronously. Asynchronous waiting is that the stream as a resource is returned to the system and can be used for other work. In this case, the system registers a callback function for a specific event.
- tryReceive functions - similar to the above, but having a certain delay for receiving data.
• The concept is closely related to the concept of asynchronous execution.
Asynchronous and parallel execution
Asynchronous execution means that the thread does not expect the result of the execution of a certain operation, using the resources of the operating system. Instead, the thread returns to the pool and can be used for other operations. In this case, a callback function is registered in the OS, which receives the result of an asynchronous operation. This function is launched upon receipt of the result (on Windows through the IO Completion ports mechanism, on Nix systems through other kernel mechanisms).
Implementation of the concept of message passing
Implementation | Tongue | Interaction type | Features | Developer |
Erlang processes | Erlang | local network | The first implementation for telecommunications equipment. It can be used for networking. A method for sending messages of the form Pid! message and receive with message matching pattern. | Ericson corp. |
Mailboxprocessor | F # | local | Uses asynchronous computing. Additionally, the concept of a response channel appears - AsyncReplyChannel, which allows you to receive a response synchronously and asynchronously. | Microsoft research |
Tpl dataflow | .NET languages | local | A set of primitives - blocks that implement receivers and data sources. | Microsoft |
Scala actors | Scala (Java machine) | local network | The implementation resembles the classic one - Erlang processes. | EPFL, Typesafe Inc. |
NodeJs | Javascript | network | Event-driven approach to application development: declarative definition of asynchronous operations and callbacks, call queue for event handler. The external interface is determined by the application developer. | Joyent Inc. |
MPI: MPICH, HP-MPI, SGI-MPI, WMPI, | C, C ++, Java, Fortran | network | The specified interface for the interaction of hosts. A single executable code for all nodes with a choice of execution branch by process identifier. | Microsoft, HP, SGI, Argonne National Laboratory, others |
Different programming languages support this concept differently. So, JavaScript (NodeJs platform) is an example of an Event-Driven language (a language that has built-in support for working with asynchronous computing). A typical NodeJs program is the declarative registration of callback functions to IO event responses. At the beginning of its execution, a queue of operations is created in which callback functions are triggered. That is, the program itself is single-threaded, but asynchronous. That is, the program itself is single-threaded, but asynchronous. In this case, the NodeJs virtual machine (based on Chrome v8 JavaScript runtime) is an example of a message passing implementation and satisfies all of the above conditions if it implements a certain network interface for interacting with other components of a distributed application (for example, a REST service).
In some languages (for example, F # - async monad, C # - async, await) there is the concept of asynchronous computation - part of the code defined by the developer, which contains both synchronous and asynchronous operations. Also, it is possible to start calculations in a parallel stream, cancel calculations, make synchronous start.
Message Passing Concept Examples
The concept of message passing was first introduced in the Erlang language (functional language with dynamic typing), which was developed by Ericson for specialized telecommunication equipment. Erlang processes are the components described earlier. Their creation and data exchange between them, unlike OS processes, does not require a significant temporary resource. Modern functional languages such as Scala (Java platform) and F # (.NET platform) took message passing implementation from Erlang. Scala agents can exist both within the same OS process and in different processes on different computers. The principles of working with them are similar to the principles of Erlang processes. F # offers a slightly different approach - MailboxProcessor. You can also find your own message passing implementation features in the TPL Dataflow library,
Networking is built on the principles of message passing. Here, the component is a program on a separate machine, the resources are all the hardware components of the computer + individual functions that are delegated to this computing node. Data is stored in the application process memory. The interface of interaction with other components (nodes) is determined by the specific technology, usually created on Berkley sockets. As an example of such a technology, we can cite MPI (Message passing interface). Its feature is that each node processes the same code, choosing a separate branch for processing using conditional statements using a stream identifier. Zero flow is dedicated. Network communication takes place via an interface similar to the above, (message passing concept) and uses flow identifiers to indicate the source and / or receiver of melons. Another example is the REST and SOAP services, which enable the developer to determine the network interface themselves. Although, at first glance, it seems that a certain interface does not fit into the concept of message passing in this way, it is equivalent to a set of post (send) and receive operations. So, in SOAP, a network function is called by accessing the xml envelope (envelope), which includes information about the function. Functions in REST work similarly - HTTP requests are used with a data format defined by the developer. that in this way a certain interface does not fit into the concept of message passing, it is equivalent to a set of post (send) and receive operations. So, in SOAP, a network function is called by accessing the xml envelope (envelope), which includes information about the function. Functions in REST work similarly - HTTP requests are used with a data format defined by the developer. that in this way a certain interface does not fit into the concept of message passing, it is equivalent to a set of post (send) and receive operations. So, in SOAP, a network function is called by accessing the xml envelope (envelope), which includes information about the function. Functions in REST work similarly - HTTP requests are used with a data format defined by the developer.
In further publications, MailboxProcessor F # (actively used in the HostTracker system ) and the features of working with the TPL DataFlow library will be examined in detail .