From 97981d0c30116acf3fb5bc3e3cfa5cca90109911 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 11 Sep 2023 13:45:54 +0100 Subject: Remove the get-nar-files call from the fetch changes fiber As this is quite expensive. --- nar-herder/mirror.scm | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'nar-herder') diff --git a/nar-herder/mirror.scm b/nar-herder/mirror.scm index 4ccf878..874a59b 100644 --- a/nar-herder/mirror.scm +++ b/nar-herder/mirror.scm @@ -40,13 +40,6 @@ (define (start-fetch-changes-fiber database storage-root mirror metrics-registry) - (define nar-files-metric - (or (metrics-registry-fetch-metric metrics-registry - "nar_files_total") - (make-gauge-metric metrics-registry - "nar_files_total" - #:labels '(stored)))) - (define (request-recent-changes) (define latest-recent-change (database-select-latest-recent-change-datetime database)) @@ -127,13 +120,21 @@ (assq-ref change-details 'datetime)) - (let ((new-files-count (length (narinfo-uris narinfo)))) - (metric-increment nar-files-metric - #:by new-files-count - ;; TODO This should be - ;; checked, rather than - ;; assumed to be false - #:label-values '((stored . "false")))))) + (and=> (metrics-registry-fetch-metric metrics-registry + "nar_files_total") + (lambda (metric) + ;; Just update this metric if it + ;; exists, since if it does, it + ;; should be set to a value + (let ((new-files-count + (length (narinfo-uris narinfo)))) + (metric-increment + metric + #:by new-files-count + ;; TODO This should be + ;; checked, rather than + ;; assumed to be false + #:label-values '((stored . "false")))))))) ((string=? change "removal") (let ((store-path (assq-ref change-details 'data))) (log-msg 'INFO "processing removal change for " @@ -163,9 +164,6 @@ (spawn-fiber (lambda () - ;; This will initialise the nar_files_total metric - (get-nar-files database storage-root metrics-registry) - (while #t (with-exception-handler (lambda (exn) -- cgit v1.2.3