Skip to content

Commit

Permalink
Double RocksDB Threads
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed Apr 24, 2022
1 parent 13cde98 commit 438505a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
22 changes: 19 additions & 3 deletions dev/blaze/dev/rocksdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,39 @@
[blaze.db.kv.rocksdb :as rocksdb]
[blaze.db.kv.rocksdb-spec]
[blaze.dev :refer [system]]
[clojure.spec.test.alpha :as st]))
[clojure.spec.test.alpha :as st])
(:import
[org.rocksdb Env ThreadStatus]))


;; Spec Instrumentation
(st/instrument)


(defn index-kv-store []
(get system [:blaze.db.kv/rocksdb :blaze.db/index-kv-store]))


(comment
(rocksdb/compact-range!
(get system :blaze.db.kv/rocksdb)
(index-kv-store)
:resource-as-of-index
true
1)

(rocksdb/compact-range!
(get system :blaze.db.kv/rocksdb)
(index-kv-store)
:search-param-value-index
true
1)

(mapv
(fn [^ThreadStatus status]
{:type (.name (.getThreadType status))
:operation-type (.name (.getOperationType status))
:operation-stage (.name (.getOperationStage status))
:operation-elapsed-time (.getOperationElapsedTime status)
:db (.getDbName status)
:cf (.getCfName status)})
(.getThreadList (Env/getDefault)))
)
12 changes: 10 additions & 2 deletions modules/rocksdb/src/blaze/db/kv/rocksdb.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
[org.rocksdb
RocksDB RocksIterator WriteOptions WriteBatch Options ColumnFamilyHandle
Statistics LRUCache CompactRangeOptions Snapshot ReadOptions
StatsLevel HistogramType]))
StatsLevel HistogramType Env Priority]))


(set! *warn-on-reflection* true)
(RocksDB/loadLibrary)


(deftype RocksKvIterator [^RocksIterator i]
Expand Down Expand Up @@ -177,7 +178,6 @@
(defmethod ig/init-key ::block-cache
[_ {:keys [size-in-mb] :or {size-in-mb 128}}]
(log/info (format "Init RocksDB block cache of %d MB" size-in-mb))
(RocksDB/loadLibrary)
(LRUCache. (bit-shift-left size-in-mb 20)))


Expand All @@ -187,6 +187,14 @@
(.close ^AutoCloseable cache))


(defmethod ig/init-key ::env
[_ _]
(log/info (format "Init RocksDB environment"))
(doto (Env/getDefault)
(.setBackgroundThreads 2 Priority/HIGH)
(.setBackgroundThreads 6 Priority/LOW)))


(defmethod ig/pre-init-spec ::kv/rocksdb [_]
(s/keys :req-un [::dir ::block-cache ::stats] :opt-un [::opts]))

Expand Down
6 changes: 5 additions & 1 deletion modules/rocksdb/src/blaze/db/kv/rocksdb/spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[blaze.db.kv.rocksdb.write-options :as-alias write-options]
[clojure.spec.alpha :as s])
(:import
[org.rocksdb Cache Statistics]))
[org.rocksdb Cache Env Statistics]))


(s/def :blaze.db.kv.rocksdb/dir
Expand All @@ -15,6 +15,10 @@
#(instance? Cache %))


(s/def :blaze.db.kv.rocksdb/env
#(instance? Env %))


(s/def :blaze.db.kv.rocksdb/stats
#(instance? Statistics %))

Expand Down
4 changes: 3 additions & 1 deletion modules/rocksdb/test/blaze/db/kv/rocksdb_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
:block-cache (ig/ref ::rocksdb/block-cache)
:stats (ig/ref ::rocksdb/stats)}
::rocksdb/block-cache {}
::rocksdb/stats {}})
::rocksdb/env {}
::rocksdb/stats {}
::rocksdb/stats-collector {}})


(deftest valid-test
Expand Down
4 changes: 4 additions & 0 deletions resources/blaze.edn
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@
:blaze.db.kv.rocksdb/block-cache
{:size-in-mb #blaze/cfg ["DB_BLOCK_CACHE_SIZE" int? 128]}

:blaze.db.kv.rocksdb/env {}

:blaze.db.kv.rocksdb/stats-collector
{:stats
[["index" #blaze/ref :blaze.db.index-kv-store/stats]
Expand Down Expand Up @@ -626,6 +628,8 @@
:blaze.db.kv.rocksdb/block-cache
{:size-in-mb #blaze/cfg ["DB_BLOCK_CACHE_SIZE" int? 128]}

:blaze.db.kv.rocksdb/env {}

[:blaze.db.kv.rocksdb/stats :blaze.db.index-kv-store/stats] {}

:blaze.db.kv.rocksdb/stats-collector
Expand Down

0 comments on commit 438505a

Please sign in to comment.