RTSync Tutorial 8 - Distributed Applications

Another main aspect of RTSync is it's ability to handle distributed applications. A distributed application is one that runs simultaneously on multiple machines at once. This involves somewhat complicated network synchronization for data sharing and message passing. Fortunately, RTSync handles these complications internally, so the programmer does not need to worry about them. Actors can be located on any machine in the system and still be accessible by any machine. In fact, when one actor calls a method of another actor, they don't even need to know which machine the other is running on! This is all taken care of by RTSync's postmaster that runs internally.

In a previous tutorial, it was said that actors do not need to be declared in any particular order. So if actor A calls a method of actor B, it doesn't matter which was declared first. In fact, actor B does not even need to be declared in the file, and the compiler will not print out an error. When the program runs, the message will be sent to actor B, but if actor B is not in the local program then the postmaster will send it over the network to find a connected program that has an actor B. If none is found, then the postmaster will hold on to the message until an actor B enters the system (note that timing exceptions may occur if actor B joins too late).

How does this all work from the programmer's perspective? For this, the rt_start() function must be looked at again. There are actually two prototypes for this function:

void rt_start(actor_name, method_name, server_port = 6127,
              host = 0, host_port = 6127);
void rt_start(server_port = 6127, host = 0, host_port = 6127);

The first is the familiar one, with a default host set to zero. This means that the postmaster will not try to connect to any other computers. If a host IP address is passed (in the form of a string), then the postmaster will connect to the computer at that IP and then will become connected to all the other computers in the system. The postmaster will then run the specified method.

The second prototype is a prototype for a postmaster that does not start a method when it begins. This simply connects to the main system and then waits for any messages to be sent to this postmaster. Once a message is received, the actors on the machine will begin to run.