diff options
author | Christopher Baines <mail@cbaines.net> | 2023-07-09 16:52:35 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-07-10 18:56:31 +0100 |
commit | 7251c7d653de29f36d50b33badf05a5db983b8e7 (patch) | |
tree | 3f74252cf1f0d13d35dc1253406d9a3b92b67f7e /scripts | |
parent | 672ee6216e1d15f7f550f53017323b59f05303cb (diff) | |
download | data-service-7251c7d653de29f36d50b33badf05a5db983b8e7.tar data-service-7251c7d653de29f36d50b33badf05a5db983b8e7.tar.gz |
Stop using a pool of threads for database operations
Now that squee cooperates with suspendable ports, this is unnecessary. Use a
connection pool to still support running queries in parallel using multiple
connections.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/guix-data-service.in | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/scripts/guix-data-service.in b/scripts/guix-data-service.in index 6a41413..1a41bd4 100644 --- a/scripts/guix-data-service.in +++ b/scripts/guix-data-service.in @@ -93,11 +93,11 @@ (alist-cons 'host arg (alist-delete 'host result)))) - (option '("thread-pool-threads") #t #f + (option '("postgresql-connections") #t #f (lambda (opt name arg result) - (alist-cons 'thread-pool-threads + (alist-cons 'postgresql-connections (string->number arg) - (alist-delete 'thread-pool-threads + (alist-delete 'postgresql-connections result)))) (option '("postgresql-statement-timeout") #t #f (lambda (opt name arg result) @@ -119,7 +119,7 @@ (_ #t))) (port . 8765) (host . "0.0.0.0") - (thread-pool-threads . 16) + (postgresql-connections . 16) (postgresql-statement-timeout . 60000))) @@ -187,44 +187,6 @@ (if (assoc-ref opts 'update-database) #f #t))) - (server-thread - (call-with-new-thread - (lambda () - (with-postgresql-connection-per-thread - "web" - (lambda () - ;; Provide some visual space between the startup output and the server - ;; starting - (simple-format #t "\n\nStarting the server on http://~A:~A/\n\n" - (assq-ref opts 'host) - (assq-ref opts 'port)) - - (parameterize - ((thread-pool-channel - (make-thread-pool-channel - (floor (/ (assoc-ref opts 'thread-pool-threads) - 2)) - #:idle-seconds 60 - #:idle-thunk - close-thread-postgresql-connection)) - - (reserved-thread-pool-channel - (make-thread-pool-channel - (floor (/ (assoc-ref opts 'thread-pool-threads) - 2)) - #:idle-seconds 60 - #:idle-thunk - close-thread-postgresql-connection)) - - (thread-pool-request-timeout 10)) - - (start-guix-data-service-web-server - (assq-ref opts 'port) - (assq-ref opts 'host) - (assq-ref opts 'secret-key-base) - startup-completed))) - #:statement-timeout - (assq-ref opts 'postgresql-statement-timeout))))) (pid-file (assq-ref opts 'pid-file))) @@ -233,11 +195,6 @@ (lambda (port) (simple-format port "~A\n" (getpid))))) - (when (assoc-ref opts 'update-database) - (run-sqitch) - - (atomic-box-set! startup-completed #t)) - (call-with-new-thread (lambda () (with-postgresql-connection-per-thread @@ -247,4 +204,24 @@ (start-substitute-query-threads) - (join-thread server-thread)))) + (when (assoc-ref opts 'update-database) + (call-with-new-thread + (lambda () + (run-sqitch) + + (atomic-box-set! startup-completed #t)))) + + ;; Provide some visual space between the startup output and the + ;; server starting + (simple-format #t "\n\nStarting the server on http://~A:~A/\n\n" + (assq-ref opts 'host) + (assq-ref opts 'port)) + (start-guix-data-service-web-server + (assq-ref opts 'port) + (assq-ref opts 'host) + (assq-ref opts 'secret-key-base) + startup-completed + #:postgresql-statement-timeout + (assq-ref opts 'postgresql-statement-timeout) + #:postgresql-connections + (assq-ref opts 'postgresql-connections))))) |