-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Threading & transactions & async #4
Comments
related: rusqlite/rusqlite#697 |
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.The text was updated successfully, but these errors were encountered: