[erlang-questions] how are erlang process lightweight?

Ben Dougall bend@REDACTED
Tue Oct 3 14:45:05 CEST 2006


On Tuesday, October 3, 2006, at 12:03  pm, Richard Carlsson wrote:

>> Each process is very lightweight. I'm struggling to find out how 
>> they're lightweight. They're stackless? Is that correct?
>
> No, each process has a stack. But the stack is initially very small
> (on the order of 16-32 words, I think), and grows as needed.
>
>> What happens to a process's local variables when it's switched out of
>> control (due to coming to a point where it's waiting for a message or
>> reached its time limit)? Each process must have local variables don't
>> they? So what happens to them? Where do they get stored? If you have
>> a set of local variables per process then how is each process
>> considered so lightweight?
>
> Of course processes have local variables, and these are stored on the
> stack while the process is switched out. How much memory is used (stack
> plus heap) per process depends completely on what the process does and
> how it was written. Processes which only receive messages and respond
> to them quickly before going back to sleep, and which do not need to
> keep track of state between messages, might never need to grow their
> stacks at all, and might only use heap memory temporarily.

Sounds so similar to a thread? What's the main difference in terms of 
memory usage? Just packed more efficiently?

>> if you have hundreds of thousands of processes that's not so
>> lightweight is it?
>
> Yes it is, compared to threads which typically need at least a few K of
> allocated stack regardless of whether it will be used. Thread
> implementations have become better in recent years, but Erlang 
> processes
> are still lightweight any way you count.

So now I'm thinking the only difference between a thread and an Erlang 
process, so far as memory footprint goes, is the packing of each frame 
in the stack, and possibly the loss of some not so essential variables 
of the frame format?

I'm still puzzled by the fact that there is considered such a 
difference in resource consumption, especially in the amount of memory 
used, between a thread and an Erlang process.

Maybe it's not so much the memory footprint that is so lightweight with 
Erlang processes compared with threads, but the savings that having all 
this handled in user space gives? So Erlang processes don't give so 
much of a memory space saving, but a data-shifting-round saving?

Thanks, Ben.




More information about the erlang-questions mailing list