Process Message Queues

Evans, Matthew <>
Fri Apr 23 18:49:19 CEST 2010


Question for you all.

The message queue in Erlang follows the following rule.

Messages are put in to the end of the queue, when the receive is processed the message is tested against the first pattern. If this matches this pattern it is removed from the queue, if it doesn't match then the message is matched against the second pattern and so on. If no patterns are matched then the message is put back on the queue and the next message is taken from the queue and so on...

So I spawn the following process, and send the 4 messages below:


()1> Pid = spawn(fun() -> receive message_a -> error_logger:info_msg("Got message_a~n"); message_b -> error_logger:info_msg("got message_b~n"); message_c -> receive message_d -> error_logger:info_msg("Got message_d~n") end end end).
()2> Pid ! hello.
()3> Pid ! goodbye.
()4> Pid ! message_d.
()5> Pid ! message_e.
()6> erlang:process_info(Pid,message_queue_len).


At this point wouldn't the message queue length be 4?

I know that message_d is in the queue since this works:


()7> Pid ! message_c.

=INFO REPORT==== 23-Apr-2010::16:39:47 ===
Got message_d
** at node  **


I guess it's not too critical, but it makes it hard(er) to figure out if a message queue is filling up.



More information about the erlang-questions mailing list