What kind of virtual machine is BEAM (the Erlang V

2019-01-09 23:19发布

问题:

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?

回答1:

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.



回答2:

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 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


回答3:

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.