Skip to content

Why sqlx-sqlite use std::thread as background thread directly? #3617

Answered by abonander
SoloJiang asked this question in Q&A
Discussion options

You must be logged in to vote

Answered on Discord:

The problem with using a threadpool is that if you have fewer threads than connections, then some queries will have to wait to run until another one completes.

And if you use Tokio's blocking threadpool, keep in mind that if there are more blocking tasks than there are threads, it spawns more threads up to a very high limit, 512 by default. If you're trying to limit the number of threads that are spawned, using the blocking task pool isn't it.

You could spawn and shut down threads when connections aren't being used, but we already have a way to control that, by configuring an idle timeout on Pool. And if you're worried about how many threads get spawned, just use fewe…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SoloJiang
Comment options

Answer selected by abonander
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants