Skip to content
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

关于时间精度 #28

Open
pathbox opened this issue May 13, 2021 · 0 comments
Open

关于时间精度 #28

pathbox opened this issue May 13, 2021 · 0 comments

Comments

@pathbox
Copy link

pathbox commented May 13, 2021

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 不是一样的, 对吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant