From: Christopher Baines <mail@cbaines.net>
To: guix-devel@gnu.org
Subject: [PATCH] cuirass: Perform some database "optimization" at startup.
Date: Mon, 25 May 2020 11:15:18 +0100 [thread overview]
Message-ID: <20200525101518.17526-1-mail@cbaines.net> (raw)
Add a "optimize" step that occurs when starting up the main Curiass
process. Currently this does two things, but could be extended to do more.
The "PRAGMA optimize;" command prompts SQLite to ANALYZE tables where that
might help. The "PRAGMA wal_checkpoint(TRUNCATE);" command has SQLite process
any unprocessed changes from the WAL file, then truncate it to 0 bytes. I've
got no data to suggest this helps with performance, but I'm hoping that going
from a large WAL file to a small one occasionally might be useful.
* src/cuirass/database.scm (db-optimize): New procedure.
* bin/cuirass.in (main): Run it.
---
bin/cuirass.in | 4 ++++
src/cuirass/database.scm | 8 ++++++++
2 files changed, 12 insertions(+)
diff --git a/bin/cuirass.in b/bin/cuirass.in
index fbc7c3c..7a2d5ae 100644
--- a/bin/cuirass.in
+++ b/bin/cuirass.in
@@ -124,6 +124,10 @@ exec ${GUILE:-@GUILE@} --no-auto-compile -e main -s "$0" "$@"
(min (current-processor-count) 4))))
(prepare-git)
+ (unless (option-ref opts 'web #f)
+ (log-message "performing database optimizations")
+ (db-optimize))
+
(log-message "running Fibers on ~a kernel threads" threads)
(run-fibers
(lambda ()
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index f80585e..e81ead0 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -38,6 +38,7 @@
db-init
db-open
db-close
+ db-optimize
db-add-specification
db-remove-specification
db-get-specifications
@@ -277,6 +278,13 @@ database object."
"Close database object DB."
(sqlite-close db))
+(define* (db-optimize #:optional (db-file (%package-database)))
+ "Open the database and perform optimizations."
+ (let ((db (db-open db-file)))
+ (sqlite-exec db "PRAGMA optimize;")
+ (sqlite-exec db "PRAGMA wal_checkpoint(TRUNCATE);")
+ (db-close db)))
+
(define (last-insert-rowid db)
(vector-ref (car (sqlite-exec db "SELECT last_insert_rowid();"))
0))
--
2.26.2
next reply other threads:[~2020-05-25 10:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-25 10:15 Christopher Baines [this message]
2020-05-25 10:48 ` [PATCH] cuirass: Perform some database "optimization" at startup Danny Milosavljevic
2020-05-25 12:42 ` Christopher Baines
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200525101518.17526-1-mail@cbaines.net \
--to=mail@cbaines.net \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.