Created
August 7, 2015 18:49
-
-
Save stuarthalloway/32f0c3540cb6b2d375a9 to your computer and use it in GitHub Desktop.
(Rough) total JVM memory size of the log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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