[erlang-questions] eep: multiple patterns

Sean Hinde <>
Fri May 30 18:01:45 CEST 2008

On 30 May 2008, at 16:38, Per Melin wrote:

> 2008/5/30 Sean Hinde <>:
>> As I understand it, the problem of poor performance with large  
>> message
>> queues is not specifically related to selective receive, but is  
>> related to
>> garbage collection of a large queue however it grows.
> If I send 100k 'foo' messages and then 100k 'bar' messages to a
> process, and then do a catch-all receive until there are no messages
> left, that takes 0.03 seconds.
> If I do a selective receive of only the 'bar' messages, it takes 90  
> seconds.

There is no contradiction here. In the first test the message queue  
never grows so you do not get a slowdown.

Badly designed use of selective receive is one way to fill a message  
queue, but by no means the only way. As I understand it once a message  
has been examined and not matched it is not visited again until the  
pattern changes.

I believe that the slowdown you see is because the garbage collector  
is working very hard dealing with all the messages on the live heap.

Note I say "believe" here. This is how it was explained to me by  
someone who should know. I have not instrumented the system to prove  
it to myself.


More information about the erlang-questions mailing list