[erlang-questions] Questions about processes and message queues

Dominic Williams erlang@REDACTED
Wed Feb 4 15:40:40 CET 2009


Hello Nicola,

> i have some doubt about processes and message queues.
> What does happend if a fast process keeps sending messages to a slow
> process? Does the queue keeps growing arbitrarly or is there some kind of
> limiting mechanism ? If so, how does it work exacly?

Have you tried to see what happens if a process sends itself
messages and never reads them? In the shell:

1> F = fun (G) -> self() ! hello, G(G) end.
#Fun<erl_eval.6.13229925>
2> Report = fun (Pid, R) -> io: fwrite ("~p~n", [erlang: process_info
(Pid, [memory, message_queue_len])]), timer: sleep (5000), R(Pid, R) end.
#Fun<erl_eval.12.113037538>
3> Report (spawn (fun () -> F(F) end), Report).
[{memory,1316},{message_queue_len,0}]
[{memory,361752},{message_queue_len,22433}]
[{memory,510536},{message_queue_len,31732}]
[{memory,617176},{message_queue_len,38397}]
[{memory,705640},{message_queue_len,43926}]
[{memory,782744},{message_queue_len,48745}]
[{memory,850888},{message_queue_len,53004}]
[{memory,912008},{message_queue_len,56824}]
[{memory,966408},{message_queue_len,60224}]

As you see, the message queue just keeps growing.

The language does not allow you to limit the length of the
queue. You must design your application in such a way as to
have end-to-end flow control.

Regards,

Dominic Williams
http://dominicwilliams.net

----




More information about the erlang-questions mailing list