aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/database.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2022-10-23 11:28:37 +0100
committerChristopher Baines <mail@cbaines.net>2022-10-23 11:28:37 +0100
commitd06230fcf4fbea966966479795d5d781a156df6f (patch)
tree6f9cbb3e16382a7dff087c86357666e1ad55fbb1 /guix-data-service/database.scm
parentaaec813cba86240d5e9e6751e1743ee4f540d998 (diff)
downloaddata-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.scm10
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;")