-
|
I have a system where the tokio runtime should work as a single thread pinned to a specific CPU thread::Builder::new()
.name(thread_name.to_string())
.spawn(move || {
core_affinity::set_for_current(core);
let rt = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
// ...
})but some of the tasks that this runtime has code that could block, I was wondering if calling spawn_blocking would "leak" threads to different cores and what should I do in general to guarantee that the runtime doesn't block and that all of its threads stay in the same CPU. This is one of the sections that could block // avoid blocking the tokio runtime because of sync code blocking, does this "leak" to other CPUs?
let send_task = tokio::task::spawn_blocking(move || this.sender.send({
// blocking code...
})).await; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I kept digging the docs and I understand now that this will simply spawn a new thread which could "leak" the thread to different CPUs. I'm going to add a small thread pool which itself is pinned to the same CPU and use channels for them to communicate |
Beta Was this translation helpful? Give feedback.
I kept digging the docs and I understand now that this will simply spawn a new thread which could "leak" the thread to different CPUs.
I'm going to add a small thread pool which itself is pinned to the same CPU and use channels for them to communicate