Why is the CPU overhead of tokio tasks significantly higher than that of goroutines? #6257
-
Someone else did a benchmark: Goroutine
Tokio Task
Another tokio task version with channels:
I know that we're not supposed to use tokio for
while goroutine is designed as a "general-purpose" coroutine. I'm just curious: what was the tokio runtime doing that costed those extra CPU cycles? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
My guess would be that Go has a better implementation of |
Beta Was this translation helpful? Give feedback.
-
Is there any way to work around this in a benchmark? I had tried this, but it didn't help:
|
Beta Was this translation helpful? Give feedback.
A few thoughts:
while let Ok(i)
part of your loop kills the workers when lagged errors occur. And they can occur in your program. In general,if let Ok
andwhile let Ok
is almost always wrong due to incorrect error handling. (whereasif let Some
/while let Some
usually isn't wrong)