diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index cd3a547f3..0248a249c 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -40,13 +40,14 @@ {:parallelism (cf/get :worker-executor-parallelism 10) :prefix :worker} - :app.worker/executors-monitor - {:executors - {:default (ig/ref [::default :app.worker/executor]) - :blocking (ig/ref [::blocking :app.worker/executor]) - :worker (ig/ref [::worker :app.worker/executor])} + :app.worker/executors + {:default (ig/ref [::default :app.worker/executor]) + :worker (ig/ref [::worker :app.worker/executor]) + :blocking (ig/ref [::blocking :app.worker/executor])} - :metrics (ig/ref :app.metrics/metrics)} + :app.worker/executors-monitor + {:metrics (ig/ref :app.metrics/metrics) + :executors (ig/ref :app.worker/executors)} :app.migrations/migrations {} @@ -155,9 +156,7 @@ :msgbus (ig/ref :app.msgbus/msgbus) :public-uri (cf/get :public-uri) :audit (ig/ref :app.loggers.audit/collector) - :executors - {:default (ig/ref [::default :app.worker/executor]) - :blocking (ig/ref [::blocking :app.worker/executor])}} + :executors (ig/ref :app.worker/executors)} :app.worker/worker {:executor (ig/ref [::worker :app.worker/executor]) diff --git a/backend/src/app/metrics.clj b/backend/src/app/metrics.clj index 7dd65079f..f21d58889 100644 --- a/backend/src/app/metrics.clj +++ b/backend/src/app/metrics.clj @@ -111,6 +111,12 @@ :labels ["name"] :type :gauge} + :executors-completed-tasks + {:name "penpot_executors_completed_tasks_total" + :help "Aproximate number of completed tasks by the executor." + :labels ["name"] + :type :counter} + :executors-running-threads {:name "penpot_executors_running_threads" :help "Current number of threads with state RUNNING." diff --git a/backend/src/app/worker.clj b/backend/src/app/worker.clj index 684d2da30..96430d2e5 100644 --- a/backend/src/app/worker.clj +++ b/backend/src/app/worker.clj @@ -75,30 +75,40 @@ (s/keys :req-un [::executors ::mtx/metrics])) (defmethod ig/init-key ::executors-monitor - [_ {:keys [executors metrics interval] :or {interval 2500}}] - (letfn [(log-stats [scheduler] + [_ {:keys [executors metrics interval] :or {interval 3000}}] + (letfn [(log-stats [scheduler state] (doseq [[key ^ForkJoinPool executor] executors] - (let [labels (into-array String [(name key)])] - (mtx/run! metrics {:id :executors-active-threads - :labels labels - :val (.getPoolSize executor)}) - (mtx/run! metrics {:id :executors-running-threads - :labels labels - :val (.getRunningThreadCount executor)}) - (mtx/run! metrics {:id :executors-queued-submissions - :labels labels - :val (.getQueuedSubmissionCount executor)}))) + (let [labels (into-array String [(name key)]) + active (.getActiveThreadCount executor) + running (.getRunningThreadCount executor) + queued (.getQueuedSubmissionCount executor) + steals (.getStealCount executor) + steals-increment (- steals (or (get-in @state [key :steals]) 9)) + steals-increment (if (neg? steals-increment) 0 steals-increment)] + + (mtx/run! metrics {:id :executors-active-threads :labels labels :val active}) + (mtx/run! metrics {:id :executors-running-threads :labels labels :val running}) + (mtx/run! metrics {:id :executors-queued-submissions :labels labels :val queued}) + (mtx/run! metrics {:id :executors-completed-tasks :labels labels :inc steals-increment}) + + (swap! state update key assoc + :running running + :active active + :queued queued + :steals steals))) (when-not (.isShutdown scheduler) - (px/schedule! scheduler interval (partial log-stats scheduler))))] + (px/schedule! scheduler interval (partial log-stats scheduler state))))] - (let [scheduler (px/scheduled-pool 1)] - (px/schedule! scheduler interval (partial log-stats scheduler)) - scheduler))) + (let [scheduler (px/scheduled-pool 1) + state (atom {})] + (px/schedule! scheduler interval (partial log-stats scheduler state)) + {::scheduler scheduler + ::state state}))) (defmethod ig/halt-key! ::executors-monitor - [_ instance] - (.shutdown ^ExecutorService instance)) + [_ {:keys [::scheduler]}] + (.shutdown ^ExecutorService scheduler)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Worker diff --git a/frontend/src/app/util/snap_data.cljs b/frontend/src/app/util/snap_data.cljs index 95e0675db..8c279836d 100644 --- a/frontend/src/app/util/snap_data.cljs +++ b/frontend/src/app/util/snap_data.cljs @@ -63,14 +63,14 @@ :pt %))) grid-x-data (->> (gg/grid-snap-points frame :x) - (mapv #(array-map :type :grid-x + (mapv #(array-map :type :layout :id frame-id :pt %))) grid-y-data (->> (gg/grid-snap-points frame :y) - (mapv #(array-map :type :grid-y - :id frame-id - :pt %)))] + (mapv #(array-map :type :layout + :id frame-id + :pt %)))] (-> page-data ;; Update root frame information