forked from twosigma/Cook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.clj
235 lines (203 loc) · 8.27 KB
/
repl.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
(ns cook.sim.repl
(:require [clojure.java.shell :use sh]
[clojure.data.generators :as gen]
[clojure.pprint :as pp]
[clojure.algo.generic.functor :refer [fmap]]
[clojure.string :as string]
[clojure.math.combinatorics :as combo]
[clojure.math.numeric-tower :as math]
[datomic.api :as d]
[cook.sim.cli :as cli]
[cook.sim.database :as db]
[cook.sim.schedule :as schedule]
[cook.sim.runner :as runner]
[cook.sim.reporting :as report]
[cook.sim.reporting.groups :as groups]
[cook.sim.system :as sys]
[cook.sim.travis :as travis]
[cook.sim.util :as u]
[simulant.util :as simu]
[com.stuartsierra.component :as component]
[reloaded.repl :refer [system init start stop go reset reset-all]]
[schema.core :as s]
[incanter.core :as ic]
[incanter.stats :as is]
[incanter.charts :as chart]))
(reloaded.repl/set-init! #(sys/system "config/settings.edn"))
(defn settings
"Shortcut to obtaining the current system settings"
[]
(-> system :config :settings))
(defn sim-db
"Shortcut to obtain a reference to the Simulator Database system component"
[]
(-> system :sim-db))
(defn sim-db-val
"Shortcut to obtain a reference to the most current value
of the Simulator Database."
[]
(-> (sim-db) :conn d/db))
(defn sim-conn
"Shortcut to acquire a connection to the Simulator Database."
[]
(:conn (sim-db)))
(defn cook-db
"Shortcut to obtain a reference to the Scheduler Database system component"
[]
(-> system :cook-db))
(defn cook-db-val
"Shortcut to obtain a reference to the most current value
of the Scheduler Database."
[]
(-> (cook-db) :conn d/db))
(defn setup-database
"Shortcut to set up a new Simulator database based on current settings."
[]
(db/setup-database! (settings)))
(defn generate-schedule
"Shortcut to generate up a new job schedule based on current settings."
[]
(schedule/generate-job-schedule! (settings) "schedule.edn"))
(defn import-schedule
"Shortcut to import a work schedule into Datomic that already exists on the
filesystem, at the hardcoded location schedule.edn."
[]
(schedule/import-schedule! (sim-db) "schedule.edn"))
(defn kill-cook-db
"Shortcut to completely destroy the Cook Scheduler database. Obviously,
don't do this to anything resembling a production database!"
[]
(-> (settings) :cook-db-uri datomic.api/delete-database))
(defn list-scheds
"Shortcut to list all job schedules currently defined in the Simulator datomic
database. In order for a schedule to appear here, it must have been imported
(see above)."
[]
(schedule/list-job-schedules (sim-db)))
(defn list-sims
"Shortcut to print out some info about all simulations that have been run for
a given work schedule. The optional after param allows you to only list sims
that were started after a specific time."
([sched-id]
(list-sims sched-id #inst "0000"))
([sched-id after]
(report/list-sims (sim-db) (cook-db) sched-id after)))
(defn simulate!
"Shortcut to run a simulation for a specific schedule given the current
system configuration. Label param is mandatory; trust me, once you've run
a good number of simulations, you'll appreciate having labelled them so you
can remember which is which!"
[sched-id label]
(runner/simulate! (settings) (sim-db) sched-id label))
(defn analyze
"Shortcut to print out a rough summmary of how jobs performed for a given
simulation."
[sim-id]
(report/analyze (settings) (sim-db) (cook-db) sim-id))
(defn compare-sims
"Shortcut to write a comparison chart for a set of sim-ids to the hardcoded
file compare_chart.png, using current system components."
[sim-ids]
(report/compare-sims {:sim-db (sim-db)
:cook-db (cook-db)
:filename "compare_chart.png"
:sim-ids sim-ids}))
(defn compare-chart
"Get a reference to a comparison chart for a given metric between
specific simulation ids, and a username prefix pattern. If the username prefix
parameter is empty, jobs for all usernames will be included in the chart; otherwise,
only jobs whose username begins with the prefix will be included."
[metric sim-ids username-prefix]
(report/job-by-job-comparison-chart
:sim-db-val (sim-db-val)
:cook-db-val (cook-db-val)
:metric metric
:baseline-sim-id (first sim-ids)
:compared-sim-ids (rest sim-ids)
:sift-label (if (empty? username-prefix) "all" username-prefix)
:sift-pred #(string/starts-with? (:username %) username-prefix)))
(defn view-compare-chart
"Shortcut to open a Java UI window that shows a comparison chart for a specific
metric and set of job-ids. Optionally, a username prefix filter may be included.
If present only jobs whose username begins with the username filter will be
represented on the chart."
([metric sim-ids]
(view-compare-chart metric sim-ids ""))
([metric sim-ids username-prefix]
(ic/view (compare-chart metric sim-ids username-prefix))))
(defn knob-chart
"Gets a reference to a knob-turning chart. (see reporting.clj). If
username-prefix is supplied, only jobs whose username begins with the username
filter will be represented on the chart."
[metric sim-ids username-prefix]
(report/knob-turning-chart :sim-db (sim-db-val)
:cook-db (cook-db-val)
:metric metric
:knob :rebalancer.config/min-dru-diff
:baseline-sims (first sim-ids)
:compared-sim-sets (rest sim-ids)
:sift-label (if (empty? username-prefix) "all" username-prefix)
:sift-pred #(string/starts-with? (:username %) username-prefix)))
(defn save-knob-chart
"Shortcut to generate a knob-turning chart and save it to a specific filename.
"
([sim-ids metric]
(save-knob-chart metric sim-ids ""))
([sim-ids metric username-prefix]
(ic/save (knob-chart metric sim-ids username-prefix)
(str (name metric) "_"
(if (empty? username-prefix) "all" username-prefix)
".png")
:width 1200 :height 800)))
(defn view-knob-chart
([metric sim-ids]
(view-knob-chart metric sim-ids ""))
([metric sim-ids username-prefix]
(ic/view (knob-chart metric sim-ids username-prefix))))
(defn save-compare-chart
([sim-ids metric]
(save-compare-chart metric sim-ids ""))
([sim-ids metric username-prefix]
(ic/save (compare-chart metric sim-ids username-prefix)
(str (name metric) "_"
(if (empty? username-prefix) "all" username-prefix)
".png")
:width 1000 :height 800)))
(defn save-all-compare-graphs
[sim-ids]
(map (fn [[metric username-prefix]]
(save-compare-chart sim-ids metric username-prefix))
(combo/cartesian-product [:wait-time :overhead :turnaround :instance-count]
["" "sim" "fcat" "spark"])))
(defn save-all-knob-graphs
[sim-ids]
(map (fn [[metric username-prefix]]
(save-knob-chart sim-ids metric username-prefix))
(combo/cartesian-product [:wait-time :overhead :turnaround :instance-count]
["" "sim" "fcat" "spark"])))
(defn job-results
[sim-id]
(report/job-results (sim-db-val) (cook-db-val) sim-id))
(defn backup-cook!
[{sim-id :entity-id}]
(let [{:keys [backup-directory cook-db-uri]} settings
backup-dest (str backup-directory sim-id)]
(println "backing up cook db up to " backup-dest)
(println (sh "datomic" "backup-db" cook-db-uri backup-dest))))
(defn pull-entity
[db eid]
(d/pull db "[*]" eid))
(def dru-scale (math/expt 10 305))
(defn dru-at-scale
[dru]
(* dru dru-scale))
(defn update-min-dru-diff!
"For testing performance with various levels of pre-emption.
This will update the real Cook's settings!"
[scaled-val]
@(d/transact (:conn (cook-db)) [{:db/id :rebalancer/config
:rebalancer.config/min-dru-diff (/ scaled-val dru-scale)}]))
(defn read-preemption-settings
"Returns Cook's current pre-emption settings."
[]
(d/pull (cook-db-val) ["*"] :rebalancer/config))