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:
parent
7f1aaa5e99
commit
22eb8d44ca
1 changed files with 34 additions and 2 deletions
|
|
@ -101,9 +101,37 @@
|
|||
(%guix-data-service-metrics-registry registry)
|
||||
|
||||
(let ((finished? (make-condition))
|
||||
(priority-scheduler #f)
|
||||
(request-scheduler #f))
|
||||
(call-with-sigint
|
||||
(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
|
||||
(lambda ()
|
||||
(run-fibers
|
||||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue