concept system in category erlang

appears as: system, systems, system, The system
Erlang and OTP in Action

This is an excerpt from Manning's book Erlang and OTP in Action.

Previously, we mentioned cleaning up complex state through processes. This is basically how it happens: a process encapsulates all its state and can therefore die safely without corrupting the rest of the system. This is just as true for a group of linked processes as it is for a single process. If one of them crashes, all its collaborators also terminate, and all the complex state that was created is snuffed out of existence cleanly and easily, saving programmer time and reducing errors.

OTP applications are usually active things with running processes, a distinct runtime behavior, and a discrete lifecycle. They’re more like standalone software applications such as web browsers and web servers than they’re like typical programming-language libraries. When you start an OTP application, you generally kick off a number of long-lived processes, some of which may potentially run for the system’s entire lifetime.

At this point, you have all the parts required to start the system. To do this, you need to specify two things: which .boot file to use and which .config file to use. In this case, these files are located in the root directory of the target system. This translates to the following command line, using the –sname flag for simplicity here:

erl –sname cache –boot ./simple_cache –config ./sys

Remember that you need to have at least one contact node running (see section 9.3.2) in order to start the system; their names must match either the hardcoded default in listing 9.4 or the names in your sys.config file. These nodes also need to be started using the –sname flag (not –name) or they won’t be able to form a cluster with the cache node.

Running the previous command should produce an Erlang shell, meaning that the system has been successfully started. The SASL output is written to the file specified in your sys.config file, so startup is less verbose than before—you can inspect the contents of the log file to check that things are working. When you start a target system in production, you typically won’t want the shell to start, and you’ll generally want the system to run in the background as a daemon. (Use a remote shell from another node if you need to log in to such a system; see section 8.2.6.) All you need to do is add the flag –detached to the command line:

10.1.3. How the system manages running applications

Remember that the starting point for an OTP application is an implementation of the application behaviour, such as your sc_app module (which the .app file points to). This provides an interface for starting and stopping the application; but there is also an associated behaviour container, known as the application controller, which handles all the applications running in the system. When the application start/2 callback function has completed the startup, it should return the pid of the newly started top-level supervisor so that the container can track it. In this way, the application behaviour is similar to the gen_event behaviour described in chapter 7: a single container manages multiple behaviour implementations (compare figure 7.1).

Figure 13.5. Requests are handled in separate threads via a Java thread pool. This makes it possible to process multiple requests simultaneously, increasing the throughput of the system.