Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Busy-waiting watchdog #672

Open
belm0 opened this issue Sep 17, 2018 · 1 comment
Open

Busy-waiting watchdog #672

belm0 opened this issue Sep 17, 2018 · 1 comment

Comments

@belm0
Copy link
Member

belm0 commented Sep 17, 2018

It's easy to cause unwanted busy-waiting in tasks, either by mistake (e.g. left out a sleep() call within a periodic loop) or by poor design (e.g. relying too heavily on polling rather than events). The simplest valid Trio program which will use all headroom on the CPU is while True: trio.sleep(0).

This is potentially far more common than the "task never awaits" scenario being addressed in #596.

I'd like to find a heuristic that can detect such problematic code while avoiding false positives.

some metrics which could be employed: median task block time vs. task CPU time over last T seconds, task schedule rate, ranking task schedule rate, cumulative task CPU time over the last T seconds, cumulative CPU time of Trio scheduler over the last T seconds

@belm0
Copy link
Member Author

belm0 commented Sep 17, 2018

based on scheduler "duty cycle":

duty cycle of the trio scheduler is a percentage defined as scheduling_wall_time / total_time for a given period of interest, like 5 seconds. scheduling_wall_time is time spent in the task scheduler loop other than 1) blocking on tasks to schedule and 2) executing tasks. High duty cycle implies a busy-wait. In that case, perhaps we can assume the cause is the one or more top tasks in terms of scheduling rate. Since tasks sharing the same bad implementation can collude, we probably want to report the top task and anything within some sigma from it.

Haven't looked at the trio scheduler, so no idea if these indicators are feasible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants