Skip to content

Commit

Permalink
transact action log in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Halloway committed Feb 11, 2013
1 parent bfbc6b6 commit 09f94e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/simulant/sim.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ key specified by :service/key."
"Teardown service at the end of a sim run."
(fn [conn process service services-map] (getx service :service/type)))

;; do-nothing default
(defmethod finalize-service :default
[conn process service services-map])

(defn- start-services
[conn process]
(reduce
Expand Down Expand Up @@ -131,7 +135,7 @@ process."
(.close ^Closeable writer)
(with-open [reader (io/reader temp-file)
pbr (PushbackReader. reader)]
(transact-batch conn (form-seq pbr)))))
(transact-pbatch conn (form-seq pbr) 1000))))

(defn create-action-log
"Create an action log service for the sim."
Expand Down
10 changes: 10 additions & 0 deletions src/simulant/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
@(d/transact-async conn (mapcat identity batch))
:ok)))

(defn transact-pbatch
"Submit txes in batches of size batch-size, default is 100"
([conn txes] (transact-pbatch conn txes 100))
([conn txes batch-size]
(->> (partition-all batch-size txes)
(pmap #(d/transact-async conn (mapcat identity %)))
(map deref)
dorun)
:ok))

(defn tx-ent
"Resolve entity id to entity as of the :db-after value of a tx result"
[txresult eid]
Expand Down

0 comments on commit 09f94e1

Please # to comment.