-
Notifications
You must be signed in to change notification settings - Fork 63
Optimize the /list fetching code to not round-trip to UUID. #848
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -837,12 +837,11 @@ | |
progress-message (assoc :progress_message progress-message) | ||
sandbox-directory (assoc :sandbox_directory sandbox-directory)))) | ||
|
||
(defn fetch-job-map | ||
[db framework-id job-uuid] | ||
(defn fetch-job-map-from-entity | ||
[db framework-id job] | ||
(timers/time! | ||
(timers/timer ["cook-mesos" "internal" "fetch-job-map"]) | ||
(let [job (d/entity db [:job/uuid job-uuid]) | ||
resources (util/job-ent->resources job) | ||
(let [resources (util/job-ent->resources job) | ||
groups (:group/_job job) | ||
application (:job/application job) | ||
expected-runtime (:job/expected-runtime job) | ||
|
@@ -891,6 +890,10 @@ | |
progress-regex-string (assoc :progress-regex-string progress-regex-string) | ||
pool (assoc :pool (:pool/name pool)))))) | ||
|
||
(defn fetch-job-map | ||
[db framework-id job-uuid] | ||
(fetch-job-map-from-entity db framework-id (d/entity db [:job/uuid job-uuid]))) | ||
|
||
(defn fetch-group-live-jobs | ||
"Get all jobs from a group that are currently running or waiting (not complete)" | ||
[db guuid] | ||
|
@@ -1257,8 +1260,8 @@ | |
(histograms/defhistogram [cook-mesos api list-request-param-limit]) | ||
(histograms/defhistogram [cook-mesos api list-response-job-count]) | ||
|
||
(defn list-jobs | ||
"Queries using the params from ctx and returns the job uuids that were found" | ||
(defn list-jobents | ||
"Queries using the params from ctx and returns the jobs that were found as datomic entities." | ||
[db include-custom-executor? ctx] | ||
(timers/time! | ||
list-endpoint | ||
|
@@ -1273,20 +1276,24 @@ | |
start-ms' (or start-ms (- end-ms (-> since-hours-ago t/hours t/in-millis))) | ||
start (Date. ^long start-ms') | ||
end (Date. ^long end-ms) | ||
job-uuids (->> (timers/time! | ||
job-ents (->> (timers/time! | ||
fetch-jobs | ||
(util/get-jobs-by-user-and-states db user states start end limit | ||
name-filter-fn include-custom-executor? pool-name)) | ||
(sort-by :job/submit-time) | ||
reverse | ||
(map :job/uuid)) | ||
job-uuids (if (nil? limit) | ||
job-uuids | ||
(take limit job-uuids))] | ||
reverse) | ||
job-ents (if (nil? limit) | ||
job-ents | ||
(take limit job-ents))] | ||
(histograms/update! list-request-param-time-range-ms (- end-ms start-ms')) | ||
(histograms/update! list-request-param-limit limit) | ||
(histograms/update! list-response-job-count (count job-uuids)) | ||
job-uuids))) | ||
(histograms/update! list-response-job-count (count job-ents)) | ||
job-ents))) | ||
|
||
(defn list-jobs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this change, does anything call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes; Line 1300, jobs-list-exists? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't that path also switch to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its a lot messier/riskier because the result of list-jobs is just stuffed into ::jobs in the context, and being a global, we have to trace the context through all of the code paths; pretty much, refactor the entire /jobs endpoint dataflow (individual UUID's, /job search parameters, etc). Now, the dataflow is entirely wired to generating, and consuming uuid's. If we push entities further down, we'd have to rewire the whole /jobs set of endpoints thing to entities, or clone chunks of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but |
||
"Queries using the params from ctx and returns the job uuids that were found" | ||
[db include-custom-executor? ctx] | ||
(map :job/uuid (list-jobents db include-custom-executor? ctx))) | ||
|
||
(defn jobs-list-exist? | ||
[conn ctx] | ||
|
@@ -2285,8 +2292,8 @@ | |
:handle-ok (fn [ctx] | ||
(timers/time! | ||
(timers/timer ["cook-scheduler" "handler" "list-endpoint-duration"]) | ||
(let [job-uuids (list-jobs db false ctx)] | ||
(mapv (partial fetch-job-map db framework-id) job-uuids)))))) | ||
(let [job-ents (list-jobents db false ctx)] | ||
(mapv (partial fetch-job-map-from-entity db framework-id) job-ents)))))) | ||
|
||
;; | ||
;; /unscheduled_jobs | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anything still use
fetch-job-map
after this change?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over a dozen uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are they? Should they switch over to using the new function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render-jobs-for-response-deprecated -- /rawscheduler handler
render-instances-for-response
11 times as a convenience function in unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have
render-jobs-for-response-deprecated
andrender-instances-for-response
use the new way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats a scope question..
If we do that, then effectively we're effectively rescoping this PR to do all of #617. Do we want to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would vote to either do that in this PR or do it immediately after this in a follow-up PR. Basically, I wouldn't want the two functions to stay around for very long.