Skip to content

Conversation

@kevinlang
Copy link
Member

In db_connection I noticed that pool_size number 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_size as 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 connect functionality, or modify db_connection to not be so greedy with immediately opening connections.

@warmwaffles
Copy link
Member

This is good. We can make that sleep more configurable later. I'll toy with it some.

What I want to explore soon is if we can use a different pooling scheme where 1 connection is only allowed to write, but the other connections are free to read.

@warmwaffles warmwaffles merged commit 7c072f8 into elixir-sqlite:main Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants