Potential high IO usage by sqlite
redmie opened this issue · 1 comments
On every remote user action, one sqlite database or more is opened and then closed (as we call close()
on the rustqlite::Connection
).
This will lead to higher resource usage than needed when handing traffic as this will create many syscalls to the underlying OS (syscalls which are inherently slow).
We could in fact keep open one connection for each database before launching the web server and only use these open connections when doing actual work, only closing them when server shutdown.
This can be implemented manually or we can use a connection pool such as r2d2 to do the trick.
I think using a ready made crate may be less error prone, but at the same time I also try to be wary of pulling in new dependencies as they increase the burden on maintainers. I'm still out on this design choice there.
Your concern is right.
As far as i know,text syncing calling function/api by anki/rslib appears to use transaction to perform db operations and changes from client seems not to save to database until executing /finish . Every time full syncs are performed,a force-closing db will occur and re-open operation is required. I cannot think of a good way to do this.
As for media syncing,this may be possible.
I also try to be wary of pulling in new dependencies as they increase the burden on maintainers.
never mind !As this is a good suggestion,in order to make server safe to use,I'm willing to do this.
Add:
We could in fact keep open one connection for each database before launching the web server and only use these open connections when doing actual work, only closing them when server shutdown.
yes,I apply your method to session db,while the others (e.g. collection and media db ) are difficult or even impossible to implement. Because we cannot locate which user we will use and thus we cannot choose the correct db.
It;s probable to optimize media db.