elixir-sqlite / exqlite

An SQLite3 driver for Elixir
https://hexdocs.pm/exqlite
MIT License
208 stars 47 forks source link

rw conns #256

Closed ruslandoga closed 11 months ago

ruslandoga commented 1 year ago

This PR is similar to #255 but instead of making writes exclusive it opens two databases, one for writing and one for reading. This allows for reads to continue being served while the write is happening thanks to WAL:

  1. WAL provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently.
warmwaffles commented 1 year ago

Some issues that come to mind that will need to be explored.

  1. Native extension support. Can it be done with the two database approach?
  2. Will this work with sqlcipher compiled with the library? We'll need to be able to pass configurations for it.
  3. Will we be able to support all of the original connection options prior to this?

I wish we had a better benchmarking harness to compare using two database handles opened vs just one.

ruslandoga commented 1 year ago

@warmwaffles

  1. Yeah... select load_extension(..., ...) or any runtime configuration (via pragmas) would need to be called on both dbs, not great.
def load_extension(conn, extension) dp
  with {:ok, _} <- query(conn, "select load_extension(#{extension})"),
       {:ok, _} <- read_query(conn, "select load_extension(#{extension})"), do: :ok
end
  1. If this happens during database opening, then it's fine same as 3. In these cases we can rather easily duplicate all configuration over two databases and just fail the init if something doesn't work.

I wish we had a better benchmarking harness to compare using two database handles opened vs just one.

I'll prepare some benchmarks for the three approaches:

ruslandoga commented 11 months ago

Closing this PR as it's too complicated. But I'm still trying to find a good replacement for the current db_connection approach :)

warmwaffles commented 11 months ago

Hah, it's not a problem. I'll find some time to really dive into this more.