Skip to content

Commit

Permalink
~Jan pool debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jul 10, 2014
1 parent 3897a7f commit 3a6fd26
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.taoensso/carmine "2.7.0-SNAPSHOT"
(defproject com.taoensso.debug/carmine "2.7.0-SNAPSHOT"
:author "Peter Taoussanis <https://www.taoensso.com>"
:description "Clojure Redis client & message queue"
:url "https://github.com/ptaoussanis/carmine"
Expand Down
14 changes: 14 additions & 0 deletions src/taoensso/carmine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
;; [conn-opts & [s1 & sn :as sigs]]
[conn-opts & sigs]
`(let [[pool# conn#] (conns/pooled-conn ~conn-opts)
_# (conns/log-pool-stats pool#)

;; To support `wcar` nesting with req planning, we mimmick
;; `with-replies` stashing logic here to simulate immediate writes:
Expand Down Expand Up @@ -572,3 +573,16 @@
(wcar {} (hmget* "hkey" "a" "b"))
(wcar {} (hgetall* "hkey"))
(wcar {} (parse str/upper-case (hgetall* "hkey"))))

(defn jan-pool-debug [conn-opts & [pool-sample-p]]
(binding [conns/*pool-sample-p* (or pool-sample-p 0.01)]
(let [k "carmine:test:debug-parallel-key"]
(wcar conn-opts (set k 0))
(->> (fn [] (future (dotimes [n 100] (wcar {} (incr k)))))
(repeatedly 100) ; No. of parallel clients
(doall)
(map deref)
(dorun))
(wcar conn-opts (get k)))))

(comment (jan-pool-debug {} 0.001))
11 changes: 11 additions & 0 deletions src/taoensso/carmine/connections.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pool. Originally adapted from redis-clojure."
{:author "Peter Taoussanis"}
(:require [taoensso.encore :as encore]
[taoensso.timbre :as timbre]
[taoensso.carmine.protocol :as protocol])
(:import [java.net Socket URI]
[java.io BufferedInputStream DataInputStream BufferedOutputStream]
Expand Down Expand Up @@ -170,3 +171,13 @@
[pool (get-conn pool spec)])))
(catch Exception e
(throw (Exception. "Carmine connection error" e))))))

(def ^:dynamic *pool-sample-p* 0.01)
(defn log-pool-stats [pool]
(let [^GenericKeyedObjectPool pool (:pool pool)
active (.getNumActive pool)
idle (.getNumIdle pool)
total (+ active idle)]
(timbre/sometimes *pool-sample-p*
(println ;;timbre/debug
"Pool stats:" {:active active :idle idle :total total}))))

0 comments on commit 3a6fd26

Please sign in to comment.