fix missing lock_for_migrations callback, add solution to database is locked #37
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
In
db_connectionI noticed thatpool_sizenumber of connections are started immediately and simultaneously (all within ~1ms), and that is what is causing our "db is locked" issue.As far as I know, most db drivers in other languages use the
pool_sizeas the "maximum number of open connections", and does not open them until needed, and later closes them when not needed. Which is why we don't hit this issue in the Go driver, for example.Here is a pass at a solution, where we "buffer" the simultaneous connections by spreading them over a 50ms interval. With this added I no longer hit issues with a pool size of 10. In the future we could be more intelligent and have the buffer interval be a function of the pool size, and so on, but this should work for now.
I'm open to other ideas on this front :). We could alternatively put similar code into the exqlite
connectfunctionality, or modifydb_connectionto not be so greedy with immediately opening connections.