diff options
author | Christopher Baines <mail@cbaines.net> | 2024-08-14 21:13:55 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2024-08-14 21:13:55 +0100 |
commit | 22eb8d44ca8bb2e02d4db3f7e84d1575458d1039 (patch) | |
tree | ee0af2542edebd735d9b2fae551f05e3e8aa8bae | |
parent | 7f1aaa5e996ecdc1b6bfe17ad81ee9297c824744 (diff) | |
download | data-service-22eb8d44ca8bb2e02d4db3f7e84d1575458d1039.tar data-service-22eb8d44ca8bb2e02d4db3f7e84d1575458d1039.tar.gz |
Move the resource pools to a different thread
As the server thread can block for a while when writing big responses.
-rw-r--r-- | guix-data-service/web/server.scm | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/guix-data-service/web/server.scm b/guix-data-service/web/server.scm index cc67624..4739dd5 100644 --- a/guix-data-service/web/server.scm +++ b/guix-data-service/web/server.scm @@ -101,6 +101,7 @@ (%guix-data-service-metrics-registry registry) (let ((finished? (make-condition)) + (priority-scheduler #f) (request-scheduler #f)) (call-with-sigint (lambda () @@ -112,6 +113,33 @@ (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 + (lambda () + (run-fibers + (lambda () + (let* ((current (current-scheduler)) + (schedulers + (cons current (scheduler-remote-peers current)))) + (set! request-scheduler current) (for-each @@ -151,6 +179,8 @@ (while (not request-scheduler) (sleep 0.1)) + (while (not priority-scheduler) + (sleep 0.1)) (let ((requests-metric (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 #:destructor (lambda (conn) - (close-postgresql-connection conn "web")))) + (close-postgresql-connection conn "web")) + #:scheduler priority-scheduler)) (reserved-connection-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 #:destructor (lambda (conn) - (close-postgresql-connection conn "web-reserved")))) + (close-postgresql-connection conn "web-reserved")) + #:scheduler priority-scheduler)) (resource-pool-default-timeout 5)) |