-
Notifications
You must be signed in to change notification settings - Fork 19
/
core.clj
83 lines (76 loc) · 4.24 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(ns trombi.core
(:require [trombi.reporters.short-summary :as short-summary]
[trombi.schema :as schema]
[trombi.progress-tracker :as progress-tracker]
[schema.core :refer [validate]]
[trombi.pipeline :as pipeline]
[trombi.legacy-util :refer [legacy-reporter->reporter]]
[trombi.simulation-util :refer [create-dir
path-join
eval-if-needed
create-report-name]]
[clojure.core.async :refer [thread]]))
(def buffer-size 20000)
(defn- create-results-dir
([root] (create-results-dir root nil))
([root simulation-name]
(let [results-dir (path-join root (create-report-name simulation-name))]
(create-dir (path-join results-dir "input"))
results-dir)))
(def default-reporters [short-summary/reporter])
(defn- parse-deprecated-reporter-option [reporter simulation]
(when reporter
(println "Warn! :reporter option is deprecated. Use :reporters instead")
(legacy-reporter->reporter :custom
reporter
simulation)))
(defn- run-with-pipeline [simulation {:keys [concurrency concurrency-distribution rate rate-distribution root
timeout-in-ms context requests duration reporter reporters error-file
executor nodes progress-tracker experimental-test-runner-stats?] :as options
:or {concurrency 1
root "target/results"
executor pipeline/local-executor
nodes 1
timeout-in-ms 5000
context {}
experimental-test-runner-stats? false}}]
(validate schema/Options options)
(let [simulation-name (:name (eval-if-needed simulation))
results-dir (create-results-dir root simulation-name)
default-progress-tracker (progress-tracker/create-console-progress-tracker)
reporters (or reporters
(concat default-reporters (parse-deprecated-reporter-option reporter simulation)))]
(pipeline/run simulation (assoc options
:concurrency concurrency
:concurrency-distribution concurrency-distribution
:rate rate
:rate-distribution rate-distribution
:timeout-in-ms timeout-in-ms
:context context
:executor executor
:progress-tracker (or progress-tracker default-progress-tracker)
:default-progress-tracker default-progress-tracker
:reporters reporters
:results-dir results-dir
:nodes nodes
:batch-size buffer-size
:requests requests
:error-file (or error-file
(path-join results-dir "error.log"))
:duration duration
:experimental-test-runner-stats? experimental-test-runner-stats?))))
(defn run [simulation {:keys [reporters] :as options}]
(let [multiple-reporters? (not (nil? reporters))
{:keys [summary]} (run-with-pipeline simulation options)]
(if multiple-reporters?
@summary
(:short @summary))))
(defn run-async [simulation {:keys [reporters] :as options}]
(let [multiple-reporters? (not (nil? reporters))
{:keys [summary force-stop-fn]} (run-with-pipeline simulation options)]
(if multiple-reporters?
{:results summary :force-stop-fn force-stop-fn}
(let [results (promise)]
(thread
(deliver results (:short @summary)))
{:results results :force-stop-fn force-stop-fn}))))