5

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?

Seki
  • 11,135
  • 7
  • 46
  • 70
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87

1 Answers1

13

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.

Community
  • 1
  • 1
tkowal
  • 9,129
  • 1
  • 27
  • 51
  • Creating processes in VM also allows cheaper message passing. And since this is managed by Erlang, you can trace those using Erlang. You can manage their lifetime, and notice (easier) when they die. And it even allows some "shared-memory" data with `ets` and `register` when you need it. And you can move compiled `beam`'s form system to system. And hot-code reloading. And much more ... In the end you are programming in actual actor model concepts, and not in the concepts imposed by the way computer is build. – mpm Oct 14 '14 at 09:22
  • 4
    Seeing the processes are **erlang** processes the erlang VM can be, and is, much smarter than the OS in creating these processes. Allocation of memory in the OS is slow, especially when it has to be thread-safe, so the erlang VM is much faster at handling memory. There are many internal memory managers and collectors specially targeted at different types of memory. It basically boils down to that the erlang VM is targeted at running erlang while the OS is much more general. – rvirding Oct 14 '14 at 11:53
  • @rvirding :please feel free to add this as answer if there are any points to be added. – HIRA THAKUR Nov 04 '14 at 10:01