[erlang-questions] eep: multiple patterns
Ulf Wiger (TN/EAB)
Fri May 30 14:37:20 CEST 2008
Per Melin skrev:
> Erlang and the BEAM have been very good to me when it
> comes to degrading gracefully under too much load, and
> then returning to normal once the load decreases. But one
> thing that has blown up my apps several times is the
> performance characteristics of selective receive.
> I'm not arguing against selective receive or "textbook
> erlang state machines". On the contrary, I only wish I
> could write them more often.
> For most cases it's fine, but still, these days I think
> long and hard before I put a process in the state of
> "I'm going to ignore some messages while I finish
> this task."
Very wise, surely.
Still, the most frequently exercised version of selective
receive in most Erlang programs is of course
And in general, that's usually sufficient. Top-level
states should not buffer messages, but rather throw
away anything they don't recognize (optionally exit,
which is what I think a gen_server should usually
do upon receipt of an unknown call or cast.)
If this is not sufficient, I guess it is almost
always because the process is handling more than
one state machine, and the logic might be reduced
to the above by using more processes.
The thing is, though, that since selective receive
is difficult to modularize, and it has known
performance problems if the message queue grows too
large, programmers will have a tendency to avoid it
even when it's absolutely necessary, in which case
they invariably end up either maintaining an impossibly
large state transition matrix, or implement selective
receive themselves (which is guaranteed to have even
worse characteristics than the built-in one.)
More information about the erlang-questions