Skip to content
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

SQLite queries happen (block) on the reactor thread #482

Open
reivilibre opened this issue Jan 12, 2022 · 3 comments
Open

SQLite queries happen (block) on the reactor thread #482

reivilibre opened this issue Jan 12, 2022 · 3 comments

Comments

@reivilibre
Copy link
Contributor

They should really be put on a thread pool so the reactor can continue and await on the results properly (like we do in Synapse).

Even if that was a single-threaded threadpool.

That said, it would be good to think about allowing multiple read-only queries to run at the same time, since they only need a shared lock and can coexist happily.

(N.B. WAL mode #472 allows some readers to coexist with a writer too — we may consider turning that on as well and what implications that has. Perhaps we should just exclude queries that are going to do updates — that way, we reduce the risk of 'database is locked' errors and so on. Or maybe we should just retry queries when that happens.)

@DMRobertson
Copy link
Contributor

There's https://github.com/omnilib/aiosqlite FWIW, though I have no idea how hard it would be to make twisted and asyncio coexist. Presumably horribly hard.

@reivilibre
Copy link
Contributor Author

There's omnilib/aiosqlite FWIW, though I have no idea how hard it would be to make twisted and asyncio coexist. Presumably horribly hard.

My experience says to avoid it at most costs — likely we should just use the same bits of Twisted that Synapse does for database queries.

@reivilibre
Copy link
Contributor Author

Also worth noting that fixing this by doing something closer to Synapse's style might mean we can turn up the logging for SQL queries, which would have been useful now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants