Skip to content

Instantly share code, notes, and snippets.

@junegunn
Last active February 5, 2016 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junegunn/1d53b795b22fe9939dc7 to your computer and use it in GitHub Desktop.
Save junegunn/1d53b795b22fe9939dc7 to your computer and use it in GitHub Desktop.
(defn recreate-table!
[]
(doto C
(admin/drop-table! :test-table)
(admin/create-table :test-table :d)))
(defn increment
[max]
(core/with-table C [t :test-table]
(core/inc t (rand-int max) {:d:foo 1})))
(doseq [num-threads [1 2 4 8 16 32 64 96]]
(recreate-table!)
(let [num-records 10000
num-iterations 500000
pool (java.util.concurrent.Executors/newFixedThreadPool num-threads)
job (partial increment num-records)
now (System/currentTimeMillis)]
(dotimes [_ num-iterations]
(.submit pool job))
(log/info "Waiting")
(doto pool
.shutdown
(.awaitTermination Long/MAX_VALUE TimeUnit/SECONDS))
(let [elapsed (- (System/currentTimeMillis) now)
tps (/ num-iterations elapsed 0.001)]
(printf "Num threads: %d, Elapsed time: %d ms, TPS: %d\n"
num-threads elapsed (int tps)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment