Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang receive message -- how is it done internally?

Tags:

erlang

How is the receive message implemented internally in erlang runtime?

When the process is waiting for a message, the execution hang on the receive. The receive is done via blocking IO, or asynchronous IO ?

If former, then it means the OS thread is blocked and if there are many process hang on receiving, the performance is bad in reason of thread context switch and also may reach the operation system's thread limitation.

like image 931
Mr.Wang from Next Door Avatar asked May 24 '13 02:05

Mr.Wang from Next Door


People also ask

What is process in Erlang?

14.1 Processes Erlang is designed for massive concurrency. Erlang processes are lightweight (grow and shrink dynamically) with small memory footprint, fast to create and terminate, and the scheduling overhead is low.

Is Erlang multithreaded?

One of the main reasons for using Erlang instead of other functional languages is Erlang's ability to handle concurrency and distributed programming. By concurrency is meant programs that can handle several threads of execution at the same time.

How to end a process in Erlang?

A process can terminate itself by calling one of the BIFs exit(Reason), erlang:error(Reason), erlang:error(Reason, Args), erlang:fault(Reason) or erlang:fault(Reason, Args). The process then terminates with reason Reason for exit/1 or {Reason,Stack} for the others.


1 Answers

Erlang processes are not corresponded to OS threads or processes. They are implemented as internal structures of Erlang VM and they are scheduled by Erlang VM. The number of OS threads which are started by Erlang VM by default is equal to CPU number. When the Erlang process is waiting for a message no one OS process or thread is blocked.

like image 83
Danil Onishchenko Avatar answered Nov 09 '22 01:11

Danil Onishchenko