From 09f94e1608be36b885b57af3ba83c839be9333f0 Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Mon, 11 Feb 2013 08:04:32 -0500 Subject: [PATCH] transact action log in parallel --- src/simulant/sim.clj | 6 +++++- src/simulant/util.clj | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/simulant/sim.clj b/src/simulant/sim.clj index b7781bd..235f4d6 100644 --- a/src/simulant/sim.clj +++ b/src/simulant/sim.clj @@ -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 @@ -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." diff --git a/src/simulant/util.clj b/src/simulant/util.clj index 4c57f0a..50e603b 100644 --- a/src/simulant/util.clj +++ b/src/simulant/util.clj @@ -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]