Performance tweak

* Moved expensive shared appender config dereferencing to cache-time wrapping.

Signed-off-by: Peter Taoussanis <p.taoussanis@gmail.com>
This commit is contained in:
Peter Taoussanis 2012-05-28 15:34:04 +07:00
parent d74de51a05
commit 269cbc1ad9

View File

@ -84,22 +84,21 @@
(defn- wrap-appender-fn (defn- wrap-appender-fn
"Wraps compile-time appender fn with additional capabilities controlled by "Wraps compile-time appender fn with additional capabilities controlled by
compile-time config: compile-time config."
* Asynchronicity.
* Runtime flood-safety control."
[appender-id {apfn :fn :keys [async? max-message-per-msecs] :as appender}] [appender-id {apfn :fn :keys [async? max-message-per-msecs] :as appender}]
(-> (->
apfn ;; Wrap to add shared appender config to args
(fn [apfn-args]
(apfn (assoc apfn-args :ap-config (@config :shared-appender-config))))
;; Wrap async ;; Wrap for asynchronicity support
((fn [apfn] ((fn [apfn]
(if-not async? (if-not async?
apfn apfn
(let [agent (agent nil :error-mode :continue)] (let [agent (agent nil :error-mode :continue)]
(fn [apfn-args] (send-off agent (fn [_] (apfn apfn-args)))))))) (fn [apfn-args] (send-off agent (fn [_] (apfn apfn-args))))))))
;; Wrap for runtime flood-safety support
;; Wrap flood-control
((fn [apfn] ((fn [apfn]
(if-not max-message-per-msecs (if-not max-message-per-msecs
apfn apfn
@ -184,9 +183,7 @@
has-throwable?# (instance? Throwable x1#) has-throwable?# (instance? Throwable x1#)
appender-args# appender-args#
{;; TODO Too much overhead for this? {:level level#
:ap-config (@config :shared-appender-config)
:level level#
:error? (>= (compare-levels level# :error) 0) :error? (>= (compare-levels level# :error) 0)
:instant (java.util.Date.) :instant (java.util.Date.)
:ns (str ~*ns*) :ns (str ~*ns*)
@ -234,7 +231,7 @@
(comment (comment
(info "foo" "bar") (info "foo" "bar")
(trace (Thread/sleep 5000)) (trace (Thread/sleep 5000))
(time (dotimes [n 10000] (trace "foo" "bar"))) ; Minimum overhead +/- 17ms (time (dotimes [n 10000] (trace "This won't log"))) ; Minimum overhead +/- 17ms
(time (dotimes [n 5] (info "foo" "bar"))) (time (dotimes [n 5] (info "foo" "bar")))
(spy (* 6 5 4 3 2 1)) (spy (* 6 5 4 3 2 1))
(info (Exception. "noes!") "bar") (info (Exception. "noes!") "bar")