Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4526

bson_get_monotonic_time has 10-16 millisecond resolution on Windows

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: APM
    • None

      Summary

      bson_get_monotonic_time() uses GetTickCount64 on Windows, which appears to have a resolution in the range of 10-16 milliseconds. This is actually quite a bit worse than what I originally assumed reading the libbson code, which implies that the returned value is just milliseconds.

      This came up while fixing some command monitoring tests on Windows for PHPC-2143. We had a few tests that assert a non-zero duration for a commandFailed or commandSucceeded event, and I noticed that these tests occasionally fail (presumably when the calculated duration is less than GetTickCount64's resolution.

      Given this limitation, is there an alternative that would make more sense on Windows? Is command monitoring the only likely case where diffing two bson_get_monotonic_time() return values might evaluate to zero? If not, perhaps bson_gettimeofday would make a better fallback.

      Environment

      • libmongoc 1.23.1
      • Windows Server 2019 64-bit
      • MSVC15 (Visual C++ 2017) x64

      How to Reproduce

      Example script: commandSucceededEvent-001.phpt

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: