ets traversal time

Joel Reymont <>
Wed Jul 15 16:53:10 CEST 2009


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,''},
        {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,''},
        {named_table,false},
        {type,set},
        {keypos,1},
        {protection,protected}]
time: 2076.814ms

---
Mac hacker with a performance bent
http://www.linkedin.com/in/joelreymont



More information about the erlang-questions mailing list