[erlang-questions] ets:lookup() versus mnesia:ets()

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Thu May 10 21:37:17 CEST 2007


 
Paulo Sérgio Almeida wrote:
> 
> Ulf Wiger (TN/EAB) wrote:
> > Hi,
> > 
> > Sure, it has been done. You seem to be aware of the drawbacks.
> 
> Do you mean, that apart from being bad software enginnering, 
> it will be as safe as using mnesia:ets/1, if mnesia keeps 
> using ets for its implementation?

This is correct, as far as I can make out of the code.
mnesia:ets(fun() -> mnesia:read({Tab,Key}) end) will
unfold into a call to ets:lookup(Tab, Key), without
any checks to see whether the table is even defined.

> > Even better than mnesia:ets/1 is to use
> > 
> > mnesia:activity(Type, fun/0),
> > 
> > where Type can be set to ets, async_dirty, sync_dirty, etc., giving 
> > you a wider array of dirtiness to choose from.
> 
> Ok. Btw, I tested mnesia:activity(ets, ...) but the runtime 
> is similar to mnesia:ets, even a bit slower (5 microseconds 
> instead of 4).

You must have a really fast machine. (:

That would be the environment lookup to see whether there's 
a custom access module (a unique feature of mnesia:activity(),
which allows for nifty add-ons like rdbms. ;)

If you really want to shave off that microsecond too, then

mnesia:activity(
   ets, fun() -> mnesia:read({T,K}) end, [], mnesia)

should do the trick, but then you remove the option of 
customizing the behaviour by installing a custom access
module (no free lunch...)

BR,
Ulf W 




More information about the erlang-questions mailing list