[erlang-questions] On selective receive (Re: eep: multiple patterns)

Per Melin <>
Sat May 31 18:03:43 CEST 2008

2008/5/31 Ulf Wiger <>:
> Actually, I assume that in just about all cases where you
> have a process that needs selective receive semantics,
> it's probably perfectly ok to set a low limit on the maximum
> length of the message queue. A buffering process could
> be placed in front of it, which might also normally do
> dispatch. It would not use selective receive, and so wouldn't
> suffer much from a large message queue.

The last time selective receive broke things for me was actually not
in my own code, but in Mnesia.

When Mnesia loads a distributed table from another node it subscribes
to table events before it starts to copy the table, and then ignores
those table event messages while it's (selectively) receiving the
table contents. Depending on the size of the table and the rate at
which the table is updated on the other node, this can make your
message queue grow until you run out of memory.

This is not a case where a long queue obviously is an error. Except
perhaps in the design.

> 2008/5/31 Ulf Wiger <>:
>> An old legacy Ericsson system implemented selective receive
>> in a way that the message queue could hold at most 6 messages.
>> Any more than that was obviously an error.
>> I think it might be useful to be able to specify such a limit as
>> a spawn option, perhaps together with maximum heap size.
>> Exceeding the limit could perhaps lead to the process being
>> killed (which might seem backwards in the case of the message
>> queue, but at least gives a visible indication), or that the sender
>> process would be suspended (which could potentially lead to the
>> whole system stopping.)
>> BR,
>> Ulf W
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list