minitrace-go icon indicating copy to clipboard operation
minitrace-go copied to clipboard

关于时间精度

Open pathbox opened this issue 3 years ago • 0 comments

Hello,

我有一个关于时间精度的问题想请教。

看了这篇文章 https://www.jianshu.com/p/d57b12d18c98

Coarse Time 若仅从高性能的角度出发来寻找计时方案,可使用 Coarse Time,它牺牲了一定的精度换取高性能。在 Linux 环境下,以 CLOCK_MONOTONIC_COARSE 作为时间源参数,通过 clock_gettime 系统调用可获取 Coarse Time。Rust 社区也提供了库 coarsetime 获取 Coarse Time: coarsetime::Instant::now() Coarse Time 性能很高,在测试环境下完成两次调用仅需要 10ns。它的精度取决于 Linux 的 jiffies 配置,默认精度为 4ms。

代码中

// Standard library's `time.Now()` will invoke two syscalls in Linux. One is `CLOCK_REALTIME` and
// another is `CLOCK_MONOTONIC`. In our case, we'd like to separate these two calls to measure
// time for performance purpose.
// `nanotime()` is identical to Linux's `clock_gettime(CLOCK_MONOTONIC, &ts)`
func monotimeNs() uint64 {
	return uint64(nanotime())
}

monotimeNs方法就是根据CLOCK_MONOTONIC_COARSE时间源吗? 那么是否有默认精度4ms的问题?

第二个问题是: 本库的实现原理好像和 https://github.com/tikv/minitrace-rust 不是一样的, 对吗?

pathbox avatar May 13 '21 09:05 pathbox