Hi,
I have two refs a1, a2. One thread modifies a1, another modifies a2.
Sample code:
http://gist.github.com/556679
If I don't ensure any ref in the transaction, the code runs in ~ 0.2
ms.
$ java -cp lib/clojure-1.2.0.jar\;src clojure.main -e "(require 'tt)
(tt/transaction-simul {:ensure2 false :ensure1 false}) (System/exit
0)"
Amounts=[-100,-100]
"Elapsed time: 0.248209 msecs"
If I ensure the non-modifying ref - the code takes variable amount of
time - ranging from 1 second to 15 seconds (10 runs).
$ java -cp lib/clojure-1.2.0.jar\;src clojure.main -e "(require 'tt)
(tt/transaction-simul {:ensure2 true :ensure1 false}) (System/exit 0)"
Amounts=[100,-100]
"Elapsed time: 7545.406736 msecs"
If I ensure both refs - the code takes even more time (on average).
$ java -cp lib/clojure-1.2.0.jar\;src clojure.main -e "(require 'tt)
(tt/transaction-simul {:ensure2 true :ensure1 true}) (System/exit 0)"
Amounts=[-100,100]
"Elapsed time: 10705.949317 msecs"
Can someone explain to me what ensure exactly does (implementation
wise)? and why its taking so much time?
Thanks!
PS: If someone is interested in the context - my first blog entry:
http://ka133.blogspot.com/2010/08/serializable-concurrency-sql-clojure.html