From fe5f7f87f0807b4280d991641d8a60aa963e215f Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 4 Apr 2021 09:01:53 +0100 Subject: Truncate the WAL if it exceeds 100MiB As database performance seems to start to drop off around this point. --- guix-build-coordinator/datastore/sqlite.scm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index f57c54e..d857a31 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -184,6 +184,18 @@ (define-method (datastore-spawn-fibers (datastore )) + (define (wal-size) + (let* ((db-filename + (slot-ref datastore 'database-file)) + (db-wal-filename + (string-append db-filename "-wal"))) + + (stat:size (stat db-wal-filename)))) + + (define MiB (* (expt 2 20) 1.)) + (define wal-size-threshold + (* 100 MiB)) + (let* ((checkpoint-duration-metric-name "datastore_wal_checkpoint_duration_seconds") (metrics-registry @@ -208,7 +220,9 @@ metrics-registry checkpoint-duration-metric-name (lambda () - (sqlite-exec db "PRAGMA wal_checkpoint(RESTART);")))))) + (if (> (wal-size) wal-size-threshold) + (sqlite-exec db "PRAGMA wal_checkpoint(TRUNCATE);") + (sqlite-exec db "PRAGMA wal_checkpoint(RESTART);"))))))) #:times 5 #:delay 5)) #:unwind? #t))) -- cgit v1.2.3