Fork me on GitHub
#clojure-austin
<
2022-08-05
>
dpsutton15:08:31

If people are using clojure.tools.logging, check and verify which logger factory you are using. For us, it was picking up slf4j instead of log4j2. slf4j will eventually delegate to log4j but it adds two orders of magnitude of slowness. So if you have any (log/trace …) in some performance critical stuff you pay a pretty big penalty (clojure.tools.logging.impl/name clojure.tools.logging/*logger-factory*) With slf4j:

logger=> (alter-var-root #'log/*logger-factory* (constantly (log.impl/slf4j-factory)))
#object[metabase.logger$eval1229$reify__1241 0x2b81c222 "metabase.logger$eval1229$reify__1241@2b81c222"]
logger=> (bench (log/trace "hi"))
Evaluation count : 26044620 in 60 samples of 434077 calls.
             Execution time mean : 2.269246 µs

logger=> (alter-var-root #'log/*logger-factory* (constantly (log.impl/log4j2-factory)))
#object[metabase.logger$eval1264$reify__1270 0x474c92ba "metabase.logger$eval1264$reify__1270@474c92ba"]
logger=> (bench (log/trace "hi"))
Evaluation count : 1528940220 in 60 samples of 25482337 calls.
             Execution time mean : 31.832879 ns
with slf4j its 2269 ns vs 31 ns with log4j directly.

dpsutton15:08:58

And it “chooses” by looking for classes from each logger in a specific order. First one it identifies is your logger. Easy to have multiple classes around and it chooses a logger arbitrarily.