diff options
author | Fiona Rowan <fiona.rowan@mongodb.com> | 2017-11-17 13:30:44 -0500 |
---|---|---|
committer | Fiona Rowan <fiona.rowan@mongodb.com> | 2017-12-07 17:28:52 -0500 |
commit | 9a2dc51f868c4877d6f140ec08a89cc4b7a0153a (patch) | |
tree | 357d7678c58b555079665162a3c6e8a1c38259a4 /src/mongo/util/platform_init.cpp | |
parent | bbebcbfde994ec14b9fabfe17779cfb5adcda211 (diff) | |
download | mongo-9a2dc51f868c4877d6f140ec08a89cc4b7a0153a.tar.gz |
SERVER-31181: ServiceExecutorAdaptive maxLatencyMicros should be greater than the minimum timer resolution of the OS
Diffstat (limited to 'src/mongo/util/platform_init.cpp')
-rw-r--r-- | src/mongo/util/platform_init.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/mongo/util/platform_init.cpp b/src/mongo/util/platform_init.cpp index 3ececf3eb0f..4aec1380523 100644 --- a/src/mongo/util/platform_init.cpp +++ b/src/mongo/util/platform_init.cpp @@ -56,12 +56,23 @@ MONGO_INITIALIZER(Behaviors_Win32)(InitializerContext*) { warning() << "Failed to increase max open files limit from default of 512 to 2048"; } - // Let's set minimum Windows Kernel quantum length to 1ms in order to allow sleepmillis() - // to support waiting periods below Windows default quantum length (which can vary per - // Windows version) - // see http://msdn.microsoft.com/en-us/library/windows/desktop/dd757624(v=vs.85).aspx - if (timeBeginPeriod(1) != TIMERR_NOERROR) { - warning() << "Failed to set minimum timer resolution to 1 millisecond"; + // Let's try to set minimum Windows Kernel quantum length to smallest viable timer resolution in + // order to allow sleepmillis() to support waiting periods below Windows default quantum length + // (which can vary per Windows version) + // See https://msdn.microsoft.com/en-us/library/windows/desktop/dd743626(v=vs.85).aspx + TIMECAPS tc; + int targetResolution = 1; + int timerResolution; + + if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { + warning() << "Failed to read timer resolution range."; + if (timeBeginPeriod(1) != TIMERR_NOERROR) { + warning() << "Failed to set minimum timer resolution to 1 millisecond."; + } + } else { + timerResolution = + std::min(std::max(int(tc.wPeriodMin), targetResolution), int(tc.wPeriodMax)); + invariant(timeBeginPeriod(timerResolution) == TIMERR_NOERROR); } return Status::OK(); |