[erlang-questions] performance vs msg queue length

Ulf Wiger <>
Mon Apr 19 20:38:12 CEST 2010

John Erickson wrote:
> Hello, I have noticed that the amount of work an erlang process gets done
> seems to decrease as its message queue grows.  In extreme cases, this is
> understandable, as when the message queue fills up all available memory.
>  However, even for more moderate cases such as ~100 messages each around
> 10kB there seems to be significant slowdown.  These are in processes that
> are not scanning the msg queue; they have a single receive block which is
> expected to match every message.  Is this expected?

Are you sure that the work generated by a message doesn't lead to
e.g. gen_server calls to other processes. Any such call would lead
to a selective receive operation, which would have to scan the
message queue.

We happened to be discussing this at the SF Erlang Factory (Patrik,
here's your reminder): in a case such as

call(P, Req) ->
   MRef = erlang:monitor(process, P),
   % Mark
   P ! {'$call', {self(),MRef}, Req},
      {MRef, Reply} -> Reply;
      {'DOWN', MRef, _, _, Reason} -> erlang:error(Reason)
   after 5000 ->

the compiler could figure out that it could skip to the
end of the message queue (the end as of % Mark above),
since the following receive clause cannot possibly match any
messages that came in before this point (they all match on
MRef which is a new and unique object).

Ulf W
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd



Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.


More information about the erlang-questions mailing list