[erlang-questions] Re: Unicast 20k messages, $500-$1000 bounty

Paulo Sérgio Almeida psa@REDACTED
Fri Jul 17 15:59:30 CEST 2009


Joel Reymont wrote:
> Can we have a final expert word on this from the OTP team?
> 
> Must we use a middleman process or can we combine {delay_send, true} 
> with directly sending to the socket when unicasting to 20k clients?

I am no such expert, but there is a simple universal rule: there are no 
miracles. If a client stops receiving then you either;

- discard messages to that client or disconnect the client or
- the messages are going to be buffered somewhere (TCP stack, message 
queues, data structures), memory consumption will grow unboundedly, 
until the VM crashes out of memory.

You cannot escape doing some flow control. I said a middleman was the 
best place to do it. As in convenient place. If you are desperate and 
want to do it with less convenience and more trouble, I guess the best 
way to obtain low latency will be:

- use port:command to write to the socket; do the loop without waiting 
for the reply messages;
- for each client keep a counter of outstanding replies from the port; 
update it as replies arrive; use ets to store this info and 
ets:update_counter;
- if that counter reaches a given value start discarding messages (i.e. 
ignore that client in the send loop); for this you can use ets:select 
with a condition on the counter to obtain the list of ports to use in 
the loop.

That's it. Have fun.
Paulo



More information about the erlang-questions mailing list