Closed trevyn closed 3 years ago
https://youtu.be/4QZ0-vIIFug?t=2568
Explains that the best thing to do for async filesystem access (SQLite is filesystem access, basically) is to use a thread pool and just glue it into a Future.
Ok, thinking about transactions and threading constraints:
Do automatic retry on SQLITE_BUSY always, with some exponential backoff. (Unless there's some way to be notified by SQLite when a command should be retried.)
Closed circa f30413b. For more details, see https://github.com/trevyn/turbosql#transactions-and-async
I’m leaning toward the best approach being
thread_local!
database connections, with SQLite handling concurrency at its level. This gives us some advantages:tokio::task::spawn_blocking(|| { ... })
; this will then use a shared database connection from the thread pool.async { thread::spawn(|| { ... }).join() }
, and then just write blocking imperative code. Because it’s our own thread, we guarantee that we have exclusive access to that DB connection.Outstanding questions:
spawn_blocking
puts us on, right? It’s ours until completion, that’s the nature of synchronous code. Which means that we could share that DB connection too. But there might be some benefit from a “fresh” DB connection, too.spawn_blocking
closure?Next steps:
thread_local!
anddbg!
the database connections on create/etc., and run some simulated loads.