简体   繁体   中英

Using ets mnesia context for read-only operations

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM