Optimize ustime() with monotonic delta#3193
Conversation
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
|
I'll change to 1ms caching time to reduce the risk of drift. I'll do it when the benchmark is complete. When we're calibrating the hardware clock frequency, we measure it in ticks per microsecond. The calibration is quite exact, but the value is rounded to a integer in ticks-per-microsecond. The worst case error due to this rounding is 0.5 ticks per microsecond. Commonly, a TSC clock has a frequency of ~2500 ticks per us and then we get an error of at most 1/5000. If we're caching gettimeofday for 100ms, we get a maximum error of 20us. With 1ms, we get a maximum error of 0.2us (rounded to 0). Given ustime() is called every microsecond, we can still save a lot by calling gettimeofday() only once in a thousand. |
|
Benchmark ran on this commit: Benchmark Comparison: unstable vs c0e16ef (averaged) - rps metricsRun Summary:
Statistical Notes:
Note: Values with (n=X, σ=Y, CV=Z%, CI99%=±W%, PI99%=±V%) indicate averages from X runs with standard deviation Y, coefficient of variation Z%, 99% confidence interval margin of error ±W% of the mean, and 99% prediction interval margin of error ±V% of the mean. CI bounds [A, B] and PI bounds [C, D] show the actual interval ranges. Configuration:
Configuration:
|
Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3193 +/- ##
============================================
+ Coverage 74.87% 74.98% +0.10%
============================================
Files 129 129
Lines 71328 71337 +9
============================================
+ Hits 53407 53490 +83
+ Misses 17921 17847 -74
🚀 New features to boost your workflow:
|
dvkashapov
left a comment
There was a problem hiding this comment.
Great results, although with 1ms diff we will be reducing amount of syscalls by 99.9% and not by 99.999% like with 100ms, the expected benefit is close to the one showed by the benchmark above.
I think we're good to go with current implementation!
Only call gettimeofday() periodically and add monotonic delta. This avoids a syscall if we have a fast monotonic clock, which we have now by default on most platforms. `ustime()` is called once per command execution. In a busy server running 1M RPS, `ustime()` is called every microsecond. By calling `gettimeofday()` only once every millisecond, we save 99.9% of these syscalls. --------- Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Only call gettimeofday() periodically and add monotonic delta. This avoids a syscall if we have a fast monotonic clock, which we have now by default on most platforms. `ustime()` is called once per command execution. In a busy server running 1M RPS, `ustime()` is called every microsecond. By calling `gettimeofday()` only once every millisecond, we save 99.9% of these syscalls. --------- Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech> Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
Only call gettimeofday() periodically and add monotonic delta. This avoids a syscall if we have a fast monotonic clock, which we have now by default on most platforms.
ustime()is called once per command execution. In a busy server running 1M RPS,ustime()is called every microsecond. By callinggettimeofday()only once every millisecond, we save 99.9% of these syscalls.