-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add controlled autovacuum for small databases #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
BenchmarkResultsCurrent status |
louiseschmidtgen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work Marco! I have some little comments then we are good to go:
| import "github.com/mattn/go-sqlite3" | ||
|
|
||
| func init() { | ||
| if err := C.sqlite3_enable_autovacuum_limit(10, 16); err != C.SQLITE_OK { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we/users going to need to tune the percentage and max pages used in auto-vacuuming?
| g.Expect(err).To(BeNil()) | ||
|
|
||
| // Expect compaction to reduce the size. | ||
| finalSize, err := server.backend.DbSize(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we please be more precise here and check whether the size aligns with the percentage we set in qlite3_enable_autovacuum_limit?
Co-authored-by: Louise K. Schmidtgen <[email protected]>
This PR enables autovacuum for small databases (which includes also new ones). This allows the database to also shrink other than grow. It depends on dqlite v1.8.2.
The vacuum operation is performed after every write transaction and is controlled by two parameters (tunable through pkg/backend/sqlite/extensions.go):
max_pageswhich is the maximum number of pages to remove per write transaction. This is useful to avoid creating very big transactions. I set the default to 16 (=16 * 4KiB = 64 KiBfreed per transaction);percentwhich is the percentage (from 0 to 100) of the database to keep.The second parameter is useful to make sure that the database doesn't do unnecessary work: it is expected that the database will continuously grow and shrink, so it is best to keep some free pages for SQLite to use. I set
10%as the default. (Which means for example that is a database grows to200 MiBand then shrinks to100 MiBwe will keep the size of the storage to110 MiB).These defaults haven't been "computed" or "measured" but are what I though it would be a good default and can certainly be changed/tuned.