7

Clojure の STM トランザクションが再試行されているかどうか、およびその頻度をポーリングする方法はありますか?

4

3 に答える 3

2

history count競合があることを示す ref を観察できます。

user=> (def my-ref (ref 0 :min-history 1))
#'user/my-ref
user=> (ref-history-count my-ref)
0
user=> (dosync (alter my-ref inc))
1
user=> (ref-history-count my-ref)
1

履歴カウントは競合を直接表すものではありません。代わりに、同時読み取りを処理するために保持された過去の値の数を表します。

履歴のサイズは と の値によって制限されminますmax。デフォルトではそれぞれ010ですが、 を作成するときに変更できますref(上記参照)。min-history0デフォルトであるため、参照に競合がない限り、通常、ゼロref-history-count以外の値が返されることはありません。

ここでさらに議論を参照してhistory countください: https://groups.google.com/forum/?fromgroups#!topic/clojure/n_MKCoa870o

clojure.coreが提供する、現時点で STM トランザクションのレートを観察する方法はないと思います。もちろん、@Chouser が履歴ストレス テストで行ったことと同様のことを行うことができます。

(dosync
    (swap! try-count inc)
    ...)

つまり、トランザクション内でカウンターをインクリメントします。増分は、トランザクションが試行されるたびに発生します。try-countより大きい場合、1トランザクションは再試行されました。

于 2013-06-18T21:36:04.883 に答える
0

この追加の実装はかなり単純です。

;; {thread-id retries-of-latest-tx}
(def tries (atom {}))

;; The max amount of tries any thread has performed
(def max-tries (atom 0))

(def ninc (fnil inc 0))

(def reporter (agent nil))

(defn report [_ tid]
  (swap! max-tries #(max % (get @tries tid 0)))
  (swap! tries update-in [tid] (constantly 0)))

(defmacro dosync [& body]
  `(clojure.core/dosync
    (swap! tries update-in [(.getId (Thread/currentThread))] ninc)
    (commute commit-id inc)
    (send reporter report (.getId (Thread/currentThread)))
    ~@body))
于 2013-06-24T08:21:21.100 に答える