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

Fix extreme CPU use in scheduler on Windows #1785

Merged
merged 1 commit into from
Mar 30, 2017

Conversation

chalcolith
Copy link
Member

This PR fixes #1625 (50% CPU usage for a simple timer demo) for Windows.

Inspired by the ancient wisdom of Joe Duffy, we now yield a Pony scheduler thread by calling Sleep(1) instead of Sleep(0). This results in a sleep of anywhere from 1 to 16 milliseconds, depending on the global value of the system timer.

The example in #1625 now runs with minimal CPU usage on my system. Comparing libponyrt.benchmarks before and after the change doesn't seem to show a significant difference.

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Mar 30, 2017
@SeanTAllen
Copy link
Member

This is important enough to trigger another release.

@SeanTAllen SeanTAllen merged commit f84f259 into ponylang:master Mar 30, 2017
ponylang-main added a commit that referenced this pull request Mar 30, 2017
@SeanTAllen
Copy link
Member

I wish I had known...

This PR fixes #1625 (50% CPU usage for a simple timer demo) for Windows.

Inspired by the ancient wisdom of Joe Duffy, we now yield a Pony scheduler thread by calling Sleep(1) instead of Sleep(0). This results in a sleep of anywhere from 1 to 16 milliseconds, depending on the global value of the system timer.

The example in #1625 now runs with minimal CPU usage on my system. Comparing libponyrt.benchmarks before and after the change doesn't seem to show a significant difference.

wasn't in the commit message, i would have added it on squashing.

That was an excellent message @kulibali, can you add things that in the body of your commit in the future so they live on in the repo?

@chalcolith
Copy link
Member Author

Ok, will do.

@jemc
Copy link
Member

jemc commented Mar 31, 2017

Sleep(0) actually only gives up the current thread’s time-slice if a thread at equal priority is ready to run.

😱

@chalcolith chalcolith deleted the busywait branch March 31, 2017 17:23
@Shorttail
Copy link

Shorttail commented Apr 1, 2017

I built ponyc from sources and can confirm that it now works in Windows 10, the timer example uses ~0% cpu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extreme busy wait
4 participants