req.send()
still depends on other threads?
#1393
-
I want to isolate HTTP requests from a Tokio event loop that blocks occasionally (due to some other unrelated tasks). An issue I am having is that the HTTP requests download very slowly and then hit the timeout. The If I do: use futures::executor; // 0.3.1
let res = tokio::task::spawn_blocking(|| {
executor::block_on(req.send())
}).await.unwrap(); I assume this would run each request on a different thread and prevent the blocked event loop from slowing down the transfers. But each HTTP download seems to go slowly even with I think the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It doesn't depend on another thread, but it does depend on a background task. The connection state management is a separate task. Regardless, they all share the same event loop and reactor, so if you're blocking any of the tasks there, you'll see degrade performance. It's strongly recommended to never block in an async task. Anything that needs to block, you can isolate into a |
Beta Was this translation helpful? Give feedback.
It doesn't depend on another thread, but it does depend on a background task. The connection state management is a separate task.
Regardless, they all share the same event loop and reactor, so if you're blocking any of the tasks there, you'll see degrade performance. It's strongly recommended to never block in an async task. Anything that needs to block, you can isolate into a
tokio::task::spawn_blocking
and await that.