console icon indicating copy to clipboard operation
console copied to clipboard

Report when a task doesn't / hasn't yielded in a while.

Open tobz opened this issue 3 years ago • 8 comments

While using tokio-console for debugging some weird behavior -- by the way, tokio-console has been great so far! -- I ended up discovering that my original issue was related to a task that never yielded. While tokio-console helped me figure this out by displaying that a companion task hadn't yet been woken up (because of the other task not yielding), it would have saved me a step or two if instead I was able to see that the non-yielding task hadn't yielded in a while/at all.

Not sure if this is simple to surface or not, but figured I'd file an issue for it regardless. :)

tobz avatar Dec 15 '21 20:12 tobz

This should be pretty easy. I think the only difficult part is that we'll have to determine how long a task should have run before yielding before adding a warning.

hawkw avatar Dec 15 '21 20:12 hawkw

@tobz if you're interested in working on this, the way we'd do it is adding a new type implementing the Warn trait: https://github.com/tokio-rs/console/blob/7d16eadc5c254f21b0f4fba31f2fdf758808a8f4/console/src/warnings.rs#L4-L47

This would be pretty similar to existing warnings, like SelfWakePercent: https://github.com/tokio-rs/console/blob/7d16eadc5c254f21b0f4fba31f2fdf758808a8f4/console/src/warnings.rs#L118-L135

I think that in the check method for this, we'd want to flag a task for the warning if all of the following are true:

  1. it is currently active (so the warning doesn't fire for tasks that are waiting to run)
  2. it has never yielded
  3. it has been running for a period of time >= some threshold (configurable?)

hawkw avatar Dec 16 '21 00:12 hawkw

we probably want to be fairly generous with the threshold, to avoid false positives...it could be something like 5-10 ms? I don't think we want the lint to fire on particularly short-lived tasks; if a task only has two or three await points in it, it's entirely possible that one instance of that task might just be lucky enough that they're all ready, and that's fine if it runs for like, 1ms or less!

hawkw avatar Dec 16 '21 00:12 hawkw

@tobz still planning on working on this?

hawkw avatar Jan 12 '22 19:01 hawkw

As interesting as it may be, I think my spare time is a bit too small at the moment to take this. :(

On Wed, Jan 12, 2022, 2:04 PM Eliza Weisman @.***> wrote:

@tobz https://github.com/tobz still planning on working on this?

— Reply to this email directly, view it on GitHub https://github.com/tokio-rs/console/issues/203#issuecomment-1011361515, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABWLF6BTMA4HXXECUSPLWDUVXGFDANCNFSM5KERGL6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

tobz avatar Jan 13 '22 04:01 tobz

Hi there, I'm learning Tokio and Rust and I think this issue could be interesting for me, if no one else is working on that I could give it a try

fbrv avatar Jan 15 '22 12:01 fbrv

@fbrv sorry i didn't reply sooner --- are you still interested in working on this issue? If so, please feel free to open a PR, or let me know if you have any questions!

hawkw avatar Apr 13 '22 16:04 hawkw

Hi @hawkw, I'm considering working on this if I can, but have a question, my assumptions may be wrong so forgive me if that's the case.

I think that in the check method for this, we'd want to flag a task for the warning if all of the following are true: it is currently active (so the warning doesn't fire for tasks that are waiting to run) it has never yielded it has been running for a period of time >= some threshold (configurable?)

Does checking if a task is running and for longer than the threshold check all 3?

My assumptions being:

  1. It is currently active - Meaning it is not awakened nor completed. Is an idle task considered active?
  2. It has never yielded - Meaning it is still running

rybertm avatar Sep 14 '22 20:09 rybertm

Hi! I saw that this went a little stale so I opened up a PR, happy to take feedback on it! Thanks

jefftt avatar Jun 22 '23 00:06 jefftt

Since https://github.com/tokio-rs/console/pull/439 got merged, should this issue be closed?

yerke avatar Feb 24 '24 05:02 yerke

Yes. I think we can close it now. Thank you!

0xPoe avatar Feb 24 '24 13:02 0xPoe