diff options
author | Christopher Baines <mail@cbaines.net> | 2022-10-23 11:28:37 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2022-10-23 11:28:37 +0100 |
commit | d06230fcf4fbea966966479795d5d781a156df6f (patch) | |
tree | 6f9cbb3e16382a7dff087c86357666e1ad55fbb1 /guix-data-service/database.scm | |
parent | aaec813cba86240d5e9e6751e1743ee4f540d998 (diff) | |
download | data-service-d06230fcf4fbea966966479795d5d781a156df6f.tar data-service-d06230fcf4fbea966966479795d5d781a156df6f.tar.gz |
Close postgresql connections when the thread pool thread is idle
I think the idle connections associated with idle threads are still taking up
memory, so especially now that you can configure an arbitrary number of
threads (and thus connections), I think it's good to close them regularly.
Diffstat (limited to 'guix-data-service/database.scm')
-rw-r--r-- | guix-data-service/database.scm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/guix-data-service/database.scm b/guix-data-service/database.scm index 1204bb4..3a39798 100644 --- a/guix-data-service/database.scm +++ b/guix-data-service/database.scm @@ -27,6 +27,7 @@ with-postgresql-connection-per-thread with-thread-postgresql-connection + close-thread-postgresql-connection with-postgresql-transaction @@ -146,6 +147,15 @@ (f conn))))) +(define (close-thread-postgresql-connection) + (let ((conn (fluid-ref %thread-postgresql-connection))) + (when conn + (pg-conn-finish conn) + (hash-remove! (%postgresql-connections-hash-table) + (current-thread)) + (fluid-set! %thread-postgresql-connection + conn)))) + (define* (with-postgresql-transaction conn f #:key always-rollback?) (exec-query conn "BEGIN;") |