How can I see the number of rollbacks in my STM in Clojure?

后端 未结 3 1153
夕颜
夕颜 2021-01-11 10:59

How can I see the number of rollbacks in my STM in Clojure?

相关标签:
3条回答
  • 2021-01-11 11:33

    You can't... unless you are willing to cheat:

    (defmacro spy-dosync [& body]
      `(let [retries# (atom -1)
             result# (dosync
                       (swap! retries# inc)
                       ~@body)]
         (println "retries count:" @retries#)
         result#))
    

    and then replace your dosync by a spy-dosync.

    0 讨论(0)
  • 2021-01-11 11:51

    If you're feeling frisky, you could hack the Clojure source and rebuild (it's easy to rebuild the Clojure source). Transaction retries happen in src/jvm/clojure/lang/LockingTransaction.java in the run() method. There's a big for loop there that goes until done or RETRY_LIMIT. The value of i when the loop exits should be the retry count.

    0 讨论(0)
  • There is STM-stress test written by Chris Houser which could be useful

    0 讨论(0)
提交回复
热议问题