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.
This commit is contained in:
parent
672ee6216e
commit
7251c7d653
15 changed files with 1292 additions and 1310 deletions
|
|
@ -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)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue