diff options
author | Christopher Baines <mail@cbaines.net> | 2021-04-04 09:01:53 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-04-04 09:01:53 +0100 |
commit | fe5f7f87f0807b4280d991641d8a60aa963e215f (patch) | |
tree | 91959c930bffba5adb063e832b39c3e79fdba8f7 | |
parent | 614c620d4cc5d86d24cb1648f1ff0bb3f588e772 (diff) | |
download | build-coordinator-fe5f7f87f0807b4280d991641d8a60aa963e215f.tar build-coordinator-fe5f7f87f0807b4280d991641d8a60aa963e215f.tar.gz |
Truncate the WAL if it exceeds 100MiB
As database performance seems to start to drop off around this point.
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 16 |
1 files changed, 15 insertions, 1 deletions
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 <sqlite-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))) |