What kind of virtual machine is BEAM (the Erlang VM)?
Asked Answered
R

3

132

From what I understand a virtual machine falls into two categories either "system virtual machine" or a "process virtual machine". It's kind of fuzzy to me where BEAM lies. Is there another kind of virtual machine I am not aware of?

Radically answered 27/5, 2013 at 19:8 Comment(0)
M
202

The Erlang VM runs as one OS process. By default it runs one OS thread per core to achieve maximum utilisation of the machine. The number of threads and on which cores they run can be set when the VM is started.

Erlang processes are implemented entirely by the Erlang VM and have no connection to either OS processes or OS threads. So even if you are running an Erlang system of over one million processes it is still only one OS process and one thread per core. So in this sense the Erlang VM is a "process virtual machine" while the Erlang system itself very much behaves like an OS and Erlang processes have very similar properties to OS processes, for example isolation. There is actually an Erlang VM, based on the BEAM, which runs on bare metal and is in fact an OS in its own right, see Erlang on Xen.

By the way, it is perfectly possible to have systems running millions of Erlang processes and it is actually done in some products, for example WhatsApp.

We were definitely thinking very much about OSes when we designed the basic Erlang environment.

Merciful answered 27/5, 2013 at 22:44 Comment(6)
@Merciful Does this mean that underlying OS does not know anything about the applications/processes running on top of Erlang VM?Maiden
@coffeMug No, from the OS point of view the Erlang VM is a normal OS process just like any other OS process. Like other OS processes it uses resources provided by the OS like memory, i/o devices, etc. So everything specifically Erlang like processes/fault-tolerance/applications/etc is handled inside the Erlang VM process.Merciful
What is the big win with Erlang on Xen - is it just faster?Cecilececiley
Would it be possible to create a BEAM+OTP 'workalike' environment using standard processes and OS features such as process management (spawn/kill/set limits) and IPC (pipes/sockets)?Drone
@RikHemsley Yes, it would be possible but only for very limited applications. Remember having 10k, 100k or even 1M processes in erlang systems is not uncommon so modelling them with OS processes would not be realistic.Merciful
Excellent answer - however, IMHO what it describes is not a virtual machine, just an interpreter.Whelm
L
56

Virtual machine is a computing system. The ultimate goal of a computing system is to execute programmed logic. From this perspective, virtual machines can be categorized into 4 types according to the level of abstraction and scope of emulation:

Type 1: Full Instruction Set Architecture (ISA) virtual machine provides a full computer system's ISA emulation or virtualization. Guest operating systems and applications can run on the top of the virtual machine as an actual computer (e.g.,VirtualBox,QEMU,XEN).

Type 2: Application Binary Interface (ABI) virtual machine provides a guest process ABI emulation. Applications against that ABI can run in the process side by side with other processes of native ABI applications (e.g.,Intel's IA-32 Execution Layer on Itanium, Transmeta's Code Morphing for X86 emulation, Apple's Rosetta translation layer for PowerPC emulation).

Type 3: Virtual ISA virtual machine provides a runtime engine so that applications coded in the virtual ISA can execute on it. Virtual ISA usually defines a high level and limited scope of ISA semantics, so it does not require the virtual machine to emulate a full computer system (e.g.,Sun Microsystem's JVM, Microsoft's Common Language Runtime, Parrot Foundation's Parrot virtual machine).

Type 4: Language Virtual Machine provides a runtime engine that executes programs expressed in a guest language. The programs are usually presented to the virtual machine in source form of the guest language, without being fully compiled into machine code beforehand. The runtime engine needs to interpret or translate the program and also fulfill certain functionalities that are abstracted by the language such as memory management (e.g., the runtime engines for Basic, Lisp, Tcl, Ruby).

The boundaries between virtual machine types are not clear-cut. For example, a language virtual machine can also employ the technique of a virtual ISA virtual machine by compiling the program into a kind of virtual ISA and then executing the code on a virtual machine of that virtual ISA.

Many VM designs, such as BEAM, crossing the boundaries. They could be fit into both 3rd and 4th categories.

source:

  1. Wikipedia
  2. Advanced Design and Implementation of Virtual Machines; Xlao-Feng LI
Lorenz answered 3/8, 2017 at 2:18 Comment(3)
It's relatively new which is why it doesn't have many upvotes. I upvoted it.Radically
Thanks for the explanation. Exactly what I was looking for.Ratcliffe
How should JS runtimes like Node.js or web browsers be categorized? Also, does Docker fit anywhere in here?Andreasandree
G
11

I assume that you've been reading http://en.wikipedia.org/wiki/Virtual_machine - under that terminology, BEAM is a "process virtual machine", just like the JVM.

Gluteus answered 27/5, 2013 at 19:57 Comment(11)
What confuses me there is that it claims that a process virtual machine runs as a normal application inside a host OS and supports a single process. But the Erlang VM has many processes running inside it which doesn't fit the description.Radically
System level processes and Erlang processes are not the same. The processes in Erlang terminology are actually user land processes, and the VM itself is a single operating system level process.Strake
With single process they probably use the Unix definition of a process. An Erlang process is a different type of process.Shillong
@Strake I understand but I don't see any distinction between OS process and language level process.Radically
@WardBekker You might be right but but nowhere is it specified.Radically
@EricdesCourtis More background about Erlang processes: #2708533Shillong
@WardBekker Thanks for the help I understand Erlang processes. I just wasn't sure what type of VM categorie Erlang fell into.Radically
I would be wary of categorizing virtual machines too much. They tend to be unique in what they do. And they are often too different to put into a specific category.Aardwolf
@IGIVECRAPANSWERS You are right but the real question is why does wikipedia do it?Radically
@EricdesCourtis Wikipedia does it because the name is heavily overloaded, like many other things in Computer Science. When people speak of Virtual Machines, it is like speaking of Object Orientation: It means different things to different people. So you need some kind of further elaboration to handle this.Aardwolf
@IGIVECRAPANSWERS Sounds to me like people don't really know what they are talking about. But yes you are correct.Radically

© 2022 - 2024 — McMap. All rights reserved.