[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},
   receive
      {MRef, Reply} -> Reply;
      {'DOWN', MRef, _, _, Reason} -> erlang:error(Reason)
   after 5000 ->
      erlang:error(timeout)
   end.

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).

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

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

www.erlang-solutions.com



More information about the erlang-questions mailing list