[erlang-questions] Surprising overhead to a Mnesia transaction:

Dan Gudmundsson dangud@REDACTED
Sat Aug 22 08:44:43 CEST 2015

On Sat, Aug 22, 2015 at 4:37 AM jim rosenblum <jim.rosenblum@REDACTED>

> Dear List
> So, now to my questions:
> 1. If I am trying to transactionally protect this sequence table, do I
> need to use sync_transaction or will async_transaction work. I don't
> understand what an ACID transaction means when there are more than 1 node
> and a transaction context which is async. If two Puts are happening on two
> different nodes, will one block until the other completes EVEN when in
> async mode?

In the normal case async should be fine, if you do not mix transactions and
dirty operations, and do not cause an overload on mnesia_tm.

In the async case a message to commit the transaction is broadcasted,
and when one reply is received the transaction returns to user code.
I.e. the transaction does not (as in the sync case) wait on every node to
return a result, which is ok since no other transaction can get a
write-lock on that record anyway until all nodes have commited the data and
released the lock.

2. is the magnitude of the performance hit seem "normal"?

The difference between dirty and transaction are huge, dirty is
a couple of ets read and ets write and a message send if remote table.

Transactions grabs locks, for write on every involved node so you have
communication internally and over the network.

3. Is there a better way to achieve what I am looking for then the above?
> Thanks very much... and some code if it helps...
> put(Key, Value, SeqNo) ->
>     F = fun() ->
> case mnesia:wread(seq, global) of
>    [] ->
> simple_put(Key, Value),
> mnesia:write(#seq{key=global, value = SeqNo});
>    [#seq{value = Old}=S] when SeqNo > Old ->
> simple_put(Key, Value),
> mnesia:write(S#seq{value = SeqNo});
>    [#seq{value = Old}] ->
> lager:warning("~p: out of order put. Map: ~p, Old: ~p, New: ~p.",
>      [?MODULE, Old, SeqNo]),
> {out_of_seq, {put, Key, Old, SeqNo}}
> end
> end,
>     case mnesia:sync_transaction(F) of
> {atomic, {out_of_seq, _}} = R ->
>    R;
> {atomic, Result} ->
>    Result;
> {aborted, Reason} ->
>    {error, Reason}
>     end.
> e
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150822/08d51522/attachment.htm>

More information about the erlang-questions mailing list