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

use monotonic timer for time delta calculations #10572

Closed
RaduBerinde opened this issue Nov 9, 2016 · 6 comments
Closed

use monotonic timer for time delta calculations #10572

RaduBerinde opened this issue Nov 9, 2016 · 6 comments
Assignees

Comments

@RaduBerinde
Copy link
Member

Things like timeouts or mutex held X for Yms should not be using time.Now which is dependent on the system clock. Most unix systems have support for a monotonic timer which can be reliably used for time period calculations.

Unfortunately there isn't a standard one in Go (golang/go#12914). But that discussion mentions a package which makes use of an internal runtime.nanotime fuction which uses a monotonic timer when available: https://github.com/aristanetworks/goarista/tree/master/monotime

Note that a monotonic timer can't be used for txn timestamps or things like that.

@tamird
Copy link
Contributor

tamird commented Dec 5, 2016

Well, I started looking into this a bit, and unfortunately it's not as easy as I'd hoped. We use time.Time for time delta calculations in all kinds of fun ways, including the return value of context.Context.Deadline(), which we then compare to the local clock reading.

Sad to say, I'm not seeing a nice way out of this one. Ideas?

@petermattis
Copy link
Collaborator

The easy solution is to wait for go1.9 and the time support for monotonic clocks.

Closing as I don't think there is anything easy to do on our end.

@RaduBerinde
Copy link
Member Author

Once we are on 1.9, it might be a good idea to have a goroutine monitor the system clock periodically and panic if it sees the clock jumping back or forward by more than the allowed clock skew.

@tamird
Copy link
Contributor

tamird commented Mar 6, 2017

We already have this code in timeutil.Now, though it currently only logs a warning.

@RaduBerinde
Copy link
Member Author

I think you mean hlc stuff not timeutil. It only detects backward jumps though, and not with any degree of reliability - if I turn the clock back 1s and then I wait 1s before doing anything that requires reading the clock, it won't get detected (I think).

@tamird
Copy link
Contributor

tamird commented Mar 7, 2017 via email

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

3 participants