Mnesia deadlock detector

Luke Gorrie <>
Sun Aug 8 21:34:40 CEST 1999


Hi all, me again,

I've been poking around with mnesia this time, and I've found some
strange behaviour apparently relating to deadlock detection.  I have a 
function which I'm using for transactions:

fun() -> mnesia:write(#test_rec{}) end

With: -record(test_rec, {id=1, date=now()}).

Running that function in mnesia:transaction/1 seems to take about
0.7ms on my machine.  However, when I run that function several times
concurrently the performance drops hugely.  It looks like Mnesia is
thinking there are deadlocks, because it cancels the transactions that 
miss out on the write lock, puts them to sleep for a random length of
time (I've experienced over 900ms), and then wakes them again (at
which point they seem to sleep/restart again if the lock isn't free).

Thought I'd report it incase it's a bug.  It sounds like
deadlock-avoidance behaviour, but all that's actually occuring here is 
contention for the write lock as far as I can tell.  Or maybe I'm
doing something silly. :-)

Code and output attached.  I'm using Mnesia 3.6.

Cheers,
Luke

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mnesia_deadlock.erl
URL: <http://erlang.org/pipermail/erlang-questions/attachments/19990809/a6f43694/attachment.ksh>
-------------- next part --------------

------------------------------------------------------------

Erlang (JAM) emulator version 47.4.1

Eshell V47.4.1  (abort with ^G)
()1> c("/home/luke/devel/erlang/mnesia_deadlock", [{outdir, "/home/luke/devel/erlang/"}]).
{ok,mnesia_deadlock}
()2> mnesia:start().
ok
()3> mnesia_deadlock:init().
{atomic,ok}
()4> mnesia_lib:set(debug, trace).
true
()5> mnesia_deadlock:run_test(3).
Mnesia(''): ** ERROR ** mnesia_tm got local EXIT from unknown process: {<0.92.0>,
                                                                                                 normal}
Mnesia(''): Restarting transaction {tid,16,<0.93.0>}: in 358ms {cyclic,'',{test_rec,1},write,write,{tid,15,<0.92.0>}}
Mnesia(''): Restarting transaction {tid,17,<0.94.0>}: in 359ms {cyclic,'',{test_rec,1},write,write,{tid,15,<0.92.0>}}
Mnesia(''): Restarting transaction {tid,17,<0.94.0>}: in 263ms {cyclic,'',{test_rec,1},write,write,{tid,16,<0.93.0>}}
Mnesia(''): ** ERROR ** mnesia_tm got local EXIT from unknown process: {<0.93.0>,
                                                                                                 normal}
ok
Mnesia(''): ** ERROR ** mnesia_tm got local EXIT from unknown process: {<0.94.0>,
                                                                                                 normal}
()6> 


More information about the erlang-questions mailing list