-
In my view, every sql operation will create a new thread to execute statement. Wouldn't that create a lot of waste of resources? I think there might be a need to manage through thread pools here. sqlx/sqlx-sqlite/src/connection/worker.rs Line 82 in 42ce24d |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 Using |
Beta Was this translation helpful? Give feedback.
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…