ets traversal time
Jim Morris
wolfmanjm@REDACTED
Thu Jul 16 02:11:17 CEST 2009
Have you tried ets:foldl which is tail recursive (presumably as it
does not specify in the docs, but it is in lists:foldl) or is there a
reason to use foldr?
If foldr is not tail recursive then I suspect that with 20K entries
the stack will get used up and or eat a lot of memory which needs to
be allocated and released, maybe even causing swapping to the disk.
On Jul 15, 7:53 am, Joel Reymont <joe...@REDACTED> wrote:
> I have a table with 20k entries that I'm traversing like this:
>
> Msg1 = {message, iolist_to_binary(mochijson2:encode(JSON))},
> F = fun({Pid, _}, _) -> Pid ! Msg1 end,
> F1 = fun() ->
> A = now(),
> ets:foldr(F, ignore, State#state.subs),
> io:format("time: ~p~n", [timer:now_diff(now(), A) /
> 1000])
> end,
> spawn_link(F1),
>
> It takes me twice as long to traverse the table the second time around.
>
> Any suggestions as to why and how to fix this?
>
> Thanks, Joel
>
> --
> Case #1
>
> info: [{memory,283357},
> {owner,<0.763.0>},
> {heir,none},
> {name,subs},
> {size,20000},
> {node,'ja...@REDACTED'},
> {named_table,false},
> {type,set},
> {keypos,1},
> {protection,protected}]
> time: 1050.958ms
>
> Case #2
> info: [{memory,283357},
> {owner,<0.763.0>},
> {heir,none},
> {name,subs},
> {size,20000},
> {node,'ja...@REDACTED'},
> {named_table,false},
> {type,set},
> {keypos,1},
> {protection,protected}]
> time: 2076.814ms
>
> ---
> Mac hacker with a performance benthttp://www.linkedin.com/in/joelreymont
>
> ________________________________________________________________
> erlang-questions mailing list. Seehttp://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
More information about the erlang-questions
mailing list