Do process in elixir/erlang work like the process in google chrome?

tl;dr -> Yes, the idea is the same, and is provided in Elixir using its language-level support for processes, message passing and Supervisors.

Longer:

Conceptually they are indeed both similar: each task (web page in chrome; process in Elixir) is run in an isolated execution context, so (as you observed) failure in one of those tasks (e.g. a browser tab in chrome; a process in Elixir) does not impact the stability of other tasks (e.g. other tabs in chrome; other tasks in your Elixir paplications) or the the host application (e.g. chrome; your Elixir app).

With elixir, each code path you put into a process is isolated from the rest of the application. This is easy to do because Elixir provides both language-level tools and fantastic abstractions in the standard libraries such as GenServer.

There are caveats to the MP approach, as with anything: it is possible for one browser tab to use all the memory on your system and bring things to its knees that way; and it is possible for one elixir process to end up with a full message box or create a deadlock due to mutual sync calls between it and another process and as a result stall other processes that may be in use … but these are not deal breakers in most cases. Just something to be aware of as you go, and certainly things you don’t need to think about as you are starting out or indeed in most application code you’ll end up writing.

That said … past the concept, the implementation of the two are completely different. Chrome uses operating system processes: these are big, expensive, and chrome has very little ability to see what is going on inside of them. This is why there is that IPC system between the webpage processes and the host browser app which reaches right down into the web render stack. Not overly pretty, and very limiting in what chrome can do, because the kernel is the real owner of things there.

In contrast, with Elixir using the BEAM virtual machine for its execution, processes are very light (~300 words of system memory overhead per process, iirc) and very fast to start and stop (this will never be a limiter in your applications), and the VM maintains oversight of these processes so it is very easy to see what is happening in your application as a whole with tools like observer. Cleanup and even recovery from failure is made very easy since all the processes are actually in the VM and Elixir provides great tools for supervision, etc.

HTH.

14 Likes