Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
Created August 7, 2015 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuarthalloway/32f0c3540cb6b2d375a9 to your computer and use it in GitHub Desktop.
Save stuarthalloway/32f0c3540cb6b2d375a9 to your computer and use it in GitHub Desktop.
(Rough) total JVM memory size of the log
;; bin/run log_size.clj DB-URI t
;; Estimates the total in-memory size of all log entries from t to end of data.
;; Scans log from t to the end, so run against a backup instead of production if possible!
(require
'[clojure.edn :as edn]
'[clojure.pprint :as pp]
'[datomic.api :as d]
'[datomic.memory-size :as size])
(defn log-size*
[conn t]
(let [log (d/log conn)
db (d/db conn)]
(->> (d/tx-range log t nil)
(reduce (fn [size logentry]
(+ size (size/memory-size logentry)))
0))))
(defn log-size
"Returns estimate of log memory size from t to end of data"
[uri t]
(let [conn (d/connect uri)]
(log-size* conn t)))
(try
(let [[db-uri t] *command-line-args*]
(prn (log-size db-uri (edn/read-string t))))
(finally
(d/shutdown true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment