-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Start measuring Ping latency closer to sending request and remove Stopwatch instance #1714
Start measuring Ping latency closer to sending request and remove Stopwatch instance #1714
Conversation
6552038
to
16a6124
Compare
Decreasing diff on #1714 to make things a bit easier to read.
Decreasing diff on #1714 to make things a bit easier to read.
Pushed up naming separate to more easily see changes here! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, a subtle but important difference here is in system clock changes. For example if a system clock is off and get corrected by an NTP sync (this happens pretty often), it'll introduce incorrect timings, since 2 absolute timestamps, as opposed to Stopwatch
(which is relative) will not be relatively correct. It could show too much time or even negative time, when corrections occur.
As an example, let's say a command starts just after midnight:
[System time: 00:00:05.500] Command starts (`timingMessage.CreatedTimestamp` is set)
[System time: 00:00:06.000] NTP time corrects, it's actually [00:00:04] (clock drift was 2 seconds)
[System time: 00:00:05.000] Command finishes
...according to profiling, this command took -500ms
, because that's that the diff in the 2 timestamps told us.
I agree on potential efficiency here, but I think we are trading correctness (no non-high performance counter systems), which is a hard sell when it comes to profiling. But maybe, the number of systems affected would be so low we're okay with that.
Thoughts? Suggestions?
Hi Nick, Other than this, what I really wanted when I was looking this code is to understand when the Ping() latency measurement starts. This is because in some projects I’m working I can see the latency calculated being much higher than the actual trips to redis when measured from outside the application. I suspect the reason was because the application was running in containers with extremely low CPU (0.2 cpu core) and the actual code path to run a Ping() call was slower than the actual roundtrip to Redis when application was busy processing other thing in parallel. Update: At least the start time for measuring latency could be quite precise if we get it in TimerMessage.WriteImpl instead, no? Update 2: going deeper in the library code I just noticed that TimerMessage is only used for Pings, so I've changed it there already to GetTimestamp on WriteImpl(). |
0b7a81c
to
1eeaf4c
Compare
1eeaf4c
to
e4328e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good - thank you!
Adding #1714 to release notes
Inspired on ValueStopWatch: https://github.com/dotnet/extensions/blob/master/src/Shared/src/ValueStopwatch/ValueStopwatch.cs, I'm removing the instance of Stopwatch from TimerMessage.
There's a change of behavior here:
We're not starting latency measurement when message is instantiated, but right before it is written to network.