Move the resource pools to a different thread

As the server thread can block for a while when writing big responses.
This commit is contained in:
Christopher Baines 2024-08-14 21:13:55 +01:00
parent 7f1aaa5e99
commit 22eb8d44ca

View file

@ -101,9 +101,37 @@
(%guix-data-service-metrics-registry registry) (%guix-data-service-metrics-registry registry)
(let ((finished? (make-condition)) (let ((finished? (make-condition))
(priority-scheduler #f)
(request-scheduler #f)) (request-scheduler #f))
(call-with-sigint (call-with-sigint
(lambda () (lambda ()
(call-with-new-thread
(lambda ()
(run-fibers
(lambda ()
(let* ((current (current-scheduler))
(schedulers
(cons current (scheduler-remote-peers current))))
(set! priority-scheduler current)
(for-each
(lambda (i sched)
(spawn-fiber
(lambda ()
(catch 'system-error
(lambda ()
(set-thread-name
(string-append "priority " (number->string i))))
(const #t)))
sched))
(iota (length schedulers))
schedulers))
(wait finished?))
#:hz 0
#:parallelism 1)))
(call-with-new-thread (call-with-new-thread
(lambda () (lambda ()
(run-fibers (run-fibers
@ -151,6 +179,8 @@
(while (not request-scheduler) (while (not request-scheduler)
(sleep 0.1)) (sleep 0.1))
(while (not priority-scheduler)
(sleep 0.1))
(let ((requests-metric (let ((requests-metric
(make-counter-metric registry "requests_total"))) (make-counter-metric registry "requests_total")))
@ -179,7 +209,8 @@ port. Also, the port used can be changed by passing the --port option.\n"
#:idle-seconds 30 #:idle-seconds 30
#:destructor #:destructor
(lambda (conn) (lambda (conn)
(close-postgresql-connection conn "web")))) (close-postgresql-connection conn "web"))
#:scheduler priority-scheduler))
(reserved-connection-pool (reserved-connection-pool
(make-resource-pool (make-resource-pool
@ -192,7 +223,8 @@ port. Also, the port used can be changed by passing the --port option.\n"
#:idle-seconds 600 #:idle-seconds 600
#:destructor #:destructor
(lambda (conn) (lambda (conn)
(close-postgresql-connection conn "web-reserved")))) (close-postgresql-connection conn "web-reserved"))
#:scheduler priority-scheduler))
(resource-pool-default-timeout 5)) (resource-pool-default-timeout 5))