Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why erlang needs a Virtual Machine?

Message passing is at the core of Erlang - "Message passing through Processes".

But the concept of Virtual Machine when it comes to erlang is still vague.

Any Help?

like image 829
HIRA THAKUR Avatar asked Oct 14 '14 08:10

HIRA THAKUR


1 Answers

There are couple of reasons for using virtual machine:

  1. Actors

    Erlang tries to be smarter than the operating system it is running on. Creating OS processes is slow and expensive. Erlang has its own light processes, scheduler that manages them and means to move them between cores. The scheduling is preemptive, which gives soft real time properties (it would be very hard to do without virtual machine)

  2. Memory management

    Allocation of memory in OS might be slow, that is why Erlang can preallocate memory and manage it internally. It is connected with data structures being immutable and garbage collecting.

  3. Instruction set

    When you have predefined set of instructions, it is easier to make optimisations. You can also create other languages on top of VM, like Elixir or Lisp Flavoured Erlang.

There are probably many, many other reasons, but those I wrote quickly from the top of my head. Main purpose of Erlang is building fault tolerant systems (the scalability thing is just byproduct of fault tolerance as Joe Armstrong explained). It was better to "restrict" user to virtual machine, where the execution can be easily controlled and give the user fault tolerance in return.

like image 55
tkowal Avatar answered Sep 28 '22 04:09

tkowal