ets vs. mnesia ram_copies

Wiger Ulf <>
Tue Mar 11 21:15:18 CET 2003


I guess we're comparing dirty_read() to ets:lookup() and
dirty_write() to ets:insert()? Transactions will of course be much
slower, but it's not really fair to compare that to ets, since the
semantics differ.

First of all, you can get *almost* ets performance by writing
like this:

mnesia:activity(
   Type = ets,
   fun() ->
      [#obj{value = Val} = Obj] = mnesia:read({obj, Key}),
      mnesia:write(Obj#obj{val = foo(Val)})
   end).

where Type can be ets | dirty | sync_dirty | transaction | sync_transaction

When Type == ets, the mnesia:read() and mnesia:write() functions are
translated to ets:lookup() and ets:insert(), with minimal overhead
(basically
a get() and a couple of external function calls for each and a get_env()
(an ets:lookup() to determine the access module for mnesia -- can be avoided
if you provide it explicitly.)

If you're doing dirty_write (e.g. with Type=dirty), mnesia will have to
perform some checks, each being basically an ets:lookup():

1) record validation (proper record name and attributes)
2) where_to_read (finding out where the physical table is)
3) sending the request to mnesia_tm process and awaiting the result
4) a number of other meta-data lookups (indeces, storage_type, replication)

/Uffe

----- Original Message -----
From: "Shawn Pearce" <>
To: <>
Sent: den 11 mars 2003 20:06
Subject: ets vs. mnesia ram_copies


> Does anyone have any tests they've put together comparing the
> performance of mnesia ram_copies (ram only tables, non replicated)
> and ets?  I'm trying to get an idea of the loss I'll have in
> performance by moving from ets to mnesia.
>
> I realize it'll be slower.  And my case isn't necessarily what
> others tested, blah, blah, blah.  I just thought I'd seen a
> message about it a while ago, but couldn't find it in the
> archives.
>
> --
> Shawn.
>
>   Q: What's tan and black and looks great on a lawyer?
>   A: A doberman.




More information about the erlang-questions mailing list