Concurrency in Erlang (Vs Java) :: Creation of Processes
Concurrency in Erlang (Vs Java) :: Creation of Processes
Erlang run its program in its own VM, just like Java, which is independent of platform.
It is referred as concurrent language at many places because threads are part of the programming
language, they do not belong to the operating system, unlike in Java. At OS level, the memory
management in the operating system protects whole pages of memory, so the smallest size that a
thread can be is the smallest size*usually 512KB) of a page. That's actually too big. This is 1 of the
major thing Erlang has modified. Usually the memory requirements for a thread is very low in
Erlang is about 512 bytes.
Creation of processes :
The processes in Erlang are created and handled in its VM. Moreover, these processes do not
create an OS thread for every created process and are lightweight. As a result, process creation
time is of the order of microseconds and independent of the number of concurrently existing
processes. While in Java, every process an underlying OS thread is created.
Handling of processes :
Apart from creation of processes, it is much cheaper to switch context, because they only switch at
known, controlled points and therefore don't have to save the entire CPU state. It is usually singlethreaded, meaning that there is no requirement to ensure thread-safety between processes.
However, it now supports SMP, but the interaction between Erlang processes on the same
scheduler/core is still very lightweight (there are separate run queues per core).
Performance Tests :
It is observed that the time taken to create an Erlang process is constant 1s up to 2,500
processes; thereafter it increases to about 3s for up to 30,000 processes. In Java, for a small
number of processes it takes about 300s to create a process. Creating more than two thousand
processes is impossible.
However, these metrics are not absolute and depends on the enviornment and the requirement.