Monday, August 30, 2010

Why process creation time in Erlang is less than Java and C#?

Below are the key points collected by me from stackoverflow, Joe Armstrong's PHD thesis and other web resources.
1. First thing to notice about Erlang is that the word "process" is used because processes do not share data and other resources while threads do share resources and memory(except stack). But still process creation is less expensive in Erlang, how? The answer to this question is that Erlang has the concept of so called "Light weight Process".

2. A newly spawned Erlang process uses 309 words of memory in the non-SMP emulator without HiPE support. Link This includes 233 words for heap and stack memory which can be increased by garbage collector as needed. While in case of Java it varies from 32Kb - 512Kb means at least 100 times more than Erlang.

3. The thread model of Java and C# is OS dependent means that when we create thread in these languages they are mapped onto native threads in someway or the other. But in case of Erlang, processes belong to language not OS, operating system sees only one process which is Erlang Run Time System(ERTS). All process creation, deletion and scheduling is done by ERTS which removes the dependency on underlying OS.

4. The above point is important because it creates a lot of difference between Erlang and other languages. In Java there is certain limit(usually some thousands) on the # threads we can create because of underlying OS but In Erlang we can create millions of threads(I have tested it).

No comments:

Post a Comment