[erlang-questions] Re: Unicast 20k messages, $500-$1000 bounty
Paulo Sérgio Almeida
psa@REDACTED
Thu Jul 16 15:57:26 CEST 2009
Hi Joel,
Joel Reymont wrote:
> I switched to ets:foldl as suggested by Jim Morris and switched to
> calculating timestamps for each message, as per the patch sent by Will
> Glozer.
ets:foldr or foldl is slow for what you need. You don't need to
accumulate or to look at the Ref, and the function passed is trivial.
For what you need you should:
- obtain the list of pids with ets:select, as in:
ets:select(State#state.subs, [{{'$1', '_'}, [], ['$1']}]).
- iterate the list in a tight loop as in:
send([], _M) -> ok;
send([H|T], M) -> H ! M, send(T, M).
I haven't measured in the case, but on a similar problem using select
and traversing the list made things faster.
But another source of inefficiency is using 2 middleman procs (as
opposed to just 1) between the pubsub and the socket.
Regards,
Paulo
More information about the erlang-questions
mailing list