Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Optimize the job fetching code to not round-trip to UUID.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Crosby committed May 7, 2018
1 parent 35b49a8 commit a87ebee
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions scheduler/src/cook/mesos/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,9 @@
progress-message (assoc :progress_message progress-message)
sandbox-directory (assoc :sandbox_directory sandbox-directory))))

(defn fetch-job-map
[db framework-id job-uuid]
(let [job (d/entity db [:job/uuid job-uuid])
resources (util/job-ent->resources job)
(defn fetch-job-map-from-entity
[db framework-id job]
(let [resources (util/job-ent->resources job)
groups (:group/_job job)
application (:job/application job)
expected-runtime (:job/expected-runtime job)
Expand Down Expand Up @@ -887,6 +886,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]
Expand Down Expand Up @@ -1252,7 +1255,7 @@
(histograms/defhistogram [cook-mesos api list-request-param-limit])
(histograms/defhistogram [cook-mesos api list-response-job-count])

(defn list-jobs
(defn list-jobents
"Queries using the params from ctx and returns the job uuids that were found"
[db include-custom-executor? ctx]
(timers/time!
Expand All @@ -1267,20 +1270,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?))
(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
"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]
Expand Down Expand Up @@ -2241,8 +2248,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
Expand Down

0 comments on commit a87ebee

Please sign in to comment.