Question

I have a mnesia ram_copies table replicated to all available nodes. Almost all operations using this table perform in dirty mode. What are consequences of using mnesia:foldl within ets context?

mnesia:activity(ets, fun() ->
  mnesia:foldl(fun(V, Acc) ->
      case V#my_table.field > 0 of
        true -> Acc;
        false -> Acc + 1
      end
    end, 0, my_table)
end).
Was it helpful?

Solution

Given that you have

  • dirty transactions everywhere else, so you're not worried about synchronization
  • ram_copies, so you don't care about checkpoints
  • all tables replicated on all nodes, so all reads are local
  • you are only reading, so remote nodes don't need to be notified

there's no difference in effect between ets and async_dirty. You may see some small speed improvement by bypassing a lot of tests that async_dirty does, but I wouldn't expect it to be a noticeable gain.

As a general practice, I'd recommend using one transaction type everywhere (defined as a macro), and only diverge when you've found real speed improvements. Otherwise you risk an error such as adding a write to your ets transaction or violating one of the other assumptions above, and then you're sunk.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top