views:

186

answers:

3

I've got very limited knowledge about Erlang, but as far as I understand, it can spawn "processes" with a very low cost.

So I wonder, what are those "processes" behind the scenes?

Are they Fibers? Threads? Continuations?

+1  A: 

They are Lightweight Processes.

Also see my question Technically why is processes in Erlang more efficient than OS threads.

Jonas
A: 

Basically they are Threads ;) One address sapce for them.

TomTom
No they aren't. Threads are much too heavyweight to implement Erlang processes. (I didn't downvote, btw.)
Marcelo Cantos
So they are totally emulated by timesharing one thread? Sorry, that sounds ridiculo9us inefficient in times where computers have more than one core ;)
TomTom
Erlang SMP is one thread per CPU core. The Erlang VM provides each process with an isolated address space, ipc and timesharing.
cthulahoops
SO basically fibers ;)
TomTom
No. Fibers use cooperative multitasking: when one fiber reaches a good stopping point, it explicitly yields control, allowing another fiber to run on the same core. Erlang processes are more like green threads: http://en.wikipedia.org/wiki/Green_threads
Warren Young
Also, threads are pretty inefficient. Each one requires a separate fixed-size stack, for one thing, typically a few MB. That means only 1024 threads per few GB of RAM in the machine, or you get swapping, which gets *really* inefficient. You can run many thousands of Erlang processes in a few GB.
Warren Young
@Warren: You can run millions in few GB.
Hynek -Pichi- Vychodil
+2  A: 

Also, from the Erlang doc:

Erlang processes are light-weight (grow and shrink dynamically) with small memory footprint, fast to create and terminate and the scheduling overhead is low.

Source: http://www.erlang.org/doc/reference_manual/processes.html

You might also want to have a look to this:

http://www.defmacro.org/ramblings/concurrency.html

When talking about Erlang processes, it says:

Erlang processes are lightweight threads. They're very cheap to start up and destroy and are very fast to switch between because under the hood they're simply functions. A typical Erlang system running on a modern desktop computer can switch between many tens of thousands such processes. Processes are switched every couple of dozen function calls which makes switches less granular but saves a tremendous amount of time normally wasted on context switching.

Roberto Aloi
So how does this differ from fibers?
Roger Alsing
For example, Ruby Fibers can't run simultaneously on different cores/CPUs (as far as I know, correct me if I'm wrong), while Erlang is very good at that.
Roberto Aloi
Isn't that more of a Ruby limitation?You can create fibers from/in threads in win32. and thus it shouldn't be any problem to make them run on multiple cores?
Roger Alsing
I guess you can run fibers on multiple cores, if the threads are preemptive. I was also reading the follwing (http://ulf.wiger.net/weblog/2008/02/06/what-is-erlang-style-concurrency/). Looks interesting.
Roberto Aloi