-
Notifications
You must be signed in to change notification settings - Fork 1k
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
HashedWheelTimerScheduler is spending 35% of execution time in sleep #4031
Comments
HashedWheelTimerScheduler
is spending 35% of execution time in sleep
I have added simple static public fields to track how much scheduler should wait (in ticks, ideally), and how much is looses because of inaccurate windows clock. var stopWatch = Stopwatch.StartNew();
#if UNSAFE_THREADING
try
{
Thread.Sleep(TimeSpan.FromMilliseconds(sleepMs));
}
catch (ThreadInterruptedException)
{
if (_workerState == WORKER_STATE_SHUTDOWN)
return long.MinValue;
}
#else
Thread.Sleep(TimeSpan.FromMilliseconds(sleepMs));
#endif
stopWatch.Stop();
_totalTicksRequiredToWaitStrict += deadline - currentTime;
_totalTicksRequiredToWait += sleepMs * TimeSpan.TicksPerMillisecond;
_totalTicksLost += stopWatch.ElapsedTicks - sleepMs * TimeSpan.TicksPerMillisecond; It turned out, that:
Scala is doing special rounding for Windows: val sleepMs = if (Helpers.isWindows) (nanos + 4 999 999) / 10 000 000 * 10 else (nanos + 999 999) / 1 000 000 I will try this and some other ideas to reduce useless waiting. Update: did not help. Still +10% to the expected waiting time. |
This is great work @IgorFedchenko - keep going with it. |
I think I have found partial solution for this problem, which may give some performance boost for long running actively scheduled scenarios. See my PR attached. |
I suspect this issue is responsible for some of the high idle CPU numbers we're seeing here: #5400 (comment) |
close akkadotnet#4031 An experiment for the time being - looking to see how it performs in benchmarks and in the test suite. Ideally, need to refactor this so it runs on the `/system` dispatcher but that will require changing the constructor arguments.
Marking this as "won't fix" - there isn't a cheaper way to do this. We've tried. Plus it barely registers on our large scale tests. |
I used Akka.IO
TcpOperationBenchmark
as a sample to apply profiling, and it turns out that it is spending ~35% of time in sleep (Sleep
function is my wrapper overThread.Sleep
that is used in scheduler). See the picture:So, 1/3 of execution time scheduler is waiting for the next tick. This may slow down actors messaging pretty much. I am going to open PR for it.
The text was updated successfully, but these errors were encountered: