-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Optimize SQLite database periodically #18612
base: master
Are you sure you want to change the base?
Conversation
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.
Personally, I am not very fond of this heuristic.
I would suggest issuing a VACUUM by periodically querying the page_count and freelist_count. And if free space is >10% then issue a VACUUM.
NOTE 1: 10% was randomly chosen
NOTE 2: There are some other heuristics discussed here. The free space one seems the most straightforward.
NOTE 3: That is my personal opinion and I don't insist on it, if you want to through with this PR.
In fact, I'm not "thrilled" with it either.
Increasing the size of the database due to the number of unused/free pages is not the main problem in our case. Since qBittorrent actively uses the database, these pages will still be re-used again later. |
Since qBittorrent usually produces records of different lengths, it is more susceptible to the problem of data/page fragmentation. Therefore, the most suitable heuristic for qBittorrent, IMO, is the one based on the number of writing/deleting made. |
You have summed my thoughts very well. For the fragmentation part, I wonder if a good enough heuristic can be obtained by using the info in DBSTAT. |
Hmm, it looks like it might be useful... |
The problem is that DBSTAT is an optional feature that is enabled at compile time, so we may find ourselves in a situation where it will not be available on the target system. At least it is disabled in SQLite plugin shipped with the official Qt binaries for Windows. So at least we'll need some kind of fallback to do without it. |
8e9c830
to
615e7b3
Compare
If SQLite DBSTAT module is available the database optimization will be performed automatically based on the value of page fragmentation.
This comment was marked as off-topic.
This comment was marked as off-topic.
Something to take into consideration: https://sqlite.org/pragma.html#pragma_auto_vacuum |
I initially rejected this idea because of the following:
In fact, right now I intend to just add an optimization command to the menu so that the user can run it manually. It would be better than nothing until automatic optimization is added someday. |
Good idea. I think the manual option would be useful even alongside with automatic optimization. |
Sure. |
It optimizes the database every time a session is loaded, and after every 10,000 writes/removes (can be useful for long-running instances).
Note, that 10,000 is an arbitrary number taken for initial implementation and I don't want to have long discussions about it (unless you can agree on some other value quickly enough). Some might also say that it would be nice to have an appropriate configuration option for it. I agree that it probably makes sense, but I would strongly not like to deal with it right now.