Fragmented tables in Mnesia
Thu Jul 10 10:34:36 CEST 2003
On Thu, 10 Jul 2003, Ulf Wiger wrote:
Uffe> On Wed, 9 Jul 2003, Erlang Questions wrote:
Uffe> >Hi, everyone.
Uffe> >Does someone know if it implies lose of performance using
Uffe> >mnesia:activity to execute reads and writes in a fragmented
Uffe> There is an overhead of one ets:lookup() per read or write
Uffe> operation when you use the mnesia_frag callback for
Uffe> non-fragmented tables. This should be regarded as
Uffe> >My question goes to indiscriminately use mnesia:activity
Uffe> >even in those cases where the table is not fragmanted
Uffe> >(yet). This way, the final user could make its own
Uffe> >fragmentations whenever he wants without having to change
Uffe> >any code line. It will be a good option if there is no
Uffe> >significative overhead in using such function.
Uffe> You could also make sure that you always use your own
Uffe> function, myDbLib:activity(Kind, Fun), which could start by
Uffe> calling mnesia:activity(Kind, Fun), and later perhaps call
Uffe> mnesia:activity(Kind, Fun, mnesia_frag).
Uffe> >Or maybe there is some other way to prevent code of
Uffe> >writting or reading from a table that could be fragmented
Uffe> >in the future. I am new in the "Mnesia Table Fragmenters
Uffe> >Club" and my experience is based on the examples found in
Uffe> >the documentation.
Uffe> I would not recommend that. My recommentation is to use your
Uffe> own wrapper to mnesia:activity() right from the start. It
Uffe> gives you the most flexibility and "no" overhead. To
Uffe> reiterate, the overhead when using mnesia_frag for
Uffe> non-fragmented tables is minimal, but there is no reason to
Uffe> lock yourself into forever using the mnesia_frag callback
Uffe> either. There are other custom callback modules, e.g. rdbms,
Uffe> and your future requirements may cause you to outgrow
Uffe> mnesia_frag as well. You may even end up wanting to write
Uffe> your own callback module (it's not that difficult). The
Uffe> trick then is not to have mnesia_frag hard-coded in 4711
Uffe> different places.
As alternative to insert tons of calls to your own activity function
myDbLib:activity(Kind, Fun), you could start by using the normal
Mnesia API. Later when you feel a need of it, you can change the
Mnesia access_module configuration parameter to some customized
access callback module (mnesia_frag, rdbms, my_own_callback...)
without doing any changes to your old code.
High Availability Software, DBMS Internals
More information about the erlang-questions