Maximum time `Future::poll` should take


I'm slowly introducing async into a large codebase at my job. One of the worries I have is the possibility of other developers using async incorrectly via excessive blocking during a call to poll. Or more specifically, if they write an async function which does some long running computation instead of delegating that computation to a spawn_blocking call for example.

Ideally I want to add in metrics that track the duration of of a poll method (very similar to tracing::instrument::Instrumented however using our own internal tracing/metric library). Ideally if the future blocks for too long, this would do something like crit! logging - letting us easily find which future did the excessive blocking and fix it.


So, my question is - is there a recommended MAX_POLL_DURATION where if the poll exceeds that duration, it would considered potentially harmful and prevent other futures from making progress? I understand there is likely not a single answer to this question as it can just "depend" - but if anyone has experience with this - that would be greatly appreciated! Since I would at least like to provide a starting point, and then incrementally adjust it over time.

Ultimately, it will depend on your application, but this article of mine has a recommendation:

It recommends 10 to 100 μs.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.