[erlang-questions] Alternative approaches to selective receive

Jay Nelson jay@REDACTED
Sat May 31 07:19:13 CEST 2008


In the "eep: multiple patterns" thread, Ulf wrote:

 > I thought I'd try to convey a feeling for just
 > how hairy the receive clauses can get. I think
 > this is the worst one.

followed by a rather largish looking chunk of
complicated receive code.

Ulf, have you guys ever gotten a message queue
that is so convoluted with mixed traffic that you
decide to split the stream?

Example:

5 sources -> 1 complicated selective receive

versus

5 sources -> 1 router -> 20 session streams

The router looks for a simpler related class of
patterns that might identify sessions or some
other set of related messages.  It then just
forwards the messages to newly minted processes
that are simpler because they don't have to
disambiguate a mixed stream.

This approach is analogous to ROK's idea of
grouping patterns by classifying them.  You could
use that tag to then route and split the stream.
The session stream processes can use selective
receive to handle messages out of order, but the
number of complicated cases might be reduced.

jay




More information about the erlang-questions mailing list