[erlang-questions] how are erlang process lightweight?

Ben Dougall <>
Tue Oct 3 13:25:37 CEST 2006


Hello Ulf,

Yes, thanks -- already read it and followed the links, and asked a 
previous similar question in that forum 
<http://lambda-the-ultimate.org/node/1692> "what are the differences 
between erlang process and pthread threads?".

Does the "What Makes Erlang Processess Tick?" thread and any of its 
answers and links address what happens to local variables of each 
process? The info that I said below in my question on this list was got 
from that "What Makes Erlang Processess Tick?" thread. Also this was 
useful: <http://www.defmacro.org/ramblings/concurrency.html> "Erlang 
Style Concurrency".

This was quite interesting from "Erlang Style Concurrency": "[Erlang 
processes are] very cheap to start up and destroy and are very fast to 
switch between because under the hood they're simply functions."

So that seems to be the thing, so far as memory footprint goes: threads 
have a stack and that stack is, as usual, made up or an indefinite 
number of frames -- potentially many/infinite -- grows per new function 
call. Whereas Erlang processes are tied very tightly (one to one) to 
functions, and a function's memory usage amount to one frame of a 
stack. So an Erlang process is limited to a frame of a stack.

Am I on the right track there? It's the memory footprint of an Erlang 
process and the memory footprint of a normal thread -- comparison of 
the two I'm interested in.

I still can't help feel that, if what I've just said is correct, that 
the Erlang process way and the normal thread way are just two different 
ways of organising the same thing and amount to the same size of memory 
footprint. If you have one thread and call three functions from that 
thread then you have a stack with three frames. If you want to do the 
same work with Erlang processes then you'd need three Erlang processes 
each using up their own frame -- so three frames. Much the same memory 
footprint, just organised/named differently. I suppose you organise 
your Erlang funtions/processes accordingly. If those three function 
calls are often done one after the other, then don't have them as 
separate functions -- have them as one function.

Any corrections of any of that would be appreciated.

Thanks, Ben.


On Tuesday, October 3, 2006, at 11:23  am, Ulf Wiger (TN/EAB) wrote:

>
> Check out the recent thread at Lambda the Ultimate:
>
> "What Makes Erlang Processess Tick?"
>
> http://lambda-the-ultimate.org/node/1742
>
> BR,
> Ulf W
>
>> -----Original Message-----
>> From: 
>> [mailto:] On Behalf Of Ben Dougall
>> Sent: den 3 oktober 2006 11:31
>> To: 
>> Subject: [erlang-questions] how are erlang process lightweight?
>>
>> Hello,
>>
>> I'm trying to find out how Erlang processes work / what
>> they're made of. I know they don't share their memory with
>> each other (have their own heaps), in order to communicate do
>> so by message passing that are serialised data. They run one
>> after another, per cpu/core. The schedular decides which
>> process should get to go next. They stop processing when they
>> come to a point where they're waiting for a message or after
>> they've been processing for a certain amount of time.
>> All this is handled by the language/runtime system and
>> happens within user space.
>>
>> Each process is very lightweight. I'm struggling to find out
>> how they're lightweight. They're stackless? Is that correct?
>> On the stack, with things that use them, local variables are
>> stored. 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? And if you don't have a set of local variables
>> per process then how can they operate reasonably -- local
>> variables persisting seem essential? A set of local variables
>> must get stored per process and if you have hundreds of
>> thousands of processes that's not so lightweight is it?
>>
>> Also how do processes correspond to functions? Is it just one
>> function per process? Processes and functions are very much
>> tied up with each other; one to one?
>>
>> Any info or pointers to things that contain info on this
>> would be much appreciated.
>>
>> Thanks, Ben.
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>




More information about the erlang-questions mailing list