Where exactly do we use mono time?
Where exactly do we use real time?
How semantics of existing APIs are affected?
What new APIs do we need to add?
Do we provide an ability to sleep till some real abs time?
Methods like time.Sub() work as before, provided that both Time values
came from the same clock. That is just common sense. time.In() could
be used to convert time values obtained from different clocks,
provided that it can figure out the difference between those clocks
with some reasonable accuracy.
Thoughts?
--
---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
When you perform just one
t.In(time.UTC) operation, for t obtained from a different time source,
you're mapping one timeline onto another. It is never possible to do
this exactly. At some point, you'll have to do something like:
t1 = now(clock1)
t2 = now(clock2)
diff = t2 - t1
But t1 and t2 already do not refer to the same moment on the universal
timeline, even if it's just by a few nanoseconds. There is an inherent
error in diff, so both of your t.In(time.UTC) operations are inexact.
You can't take the result of two inexact operations and do a strict
comparison on them. It's a problem that will affect any solution that
introduces a second clock into the picture.
Furthermore, I'm not sure that it makes sense for time.In() to
recompute the difference between the clocks on each invocation.
My concern here is that this is inherently tricky, so users will do it
incorrectly, or probably even don't realize the problem at all (all
time.Sleep function take Duration -- so just calculate Duration
between Now and Then and Sleep).
As our discussion demonstrates, converting values from one clock to
another is problematic and should be avoided unless absolutely
necessary. The conversion that your code is doing may create even more
unexpected behavior.
Ideally, functions like SetDeadline should have been based on
monotonic time to begin with. My proposal attempts to solve this by
allowing time.Time to represent values obtained from other clocks,
which lets existing functions select the appropriate clock to use
without any conversions.
It seems like there's consensus that at least time.Ticker and company should use a monotonic clock underneath.
Also from what I have seen it looks like both GCE and EC2 instances have (different) problems keeping time.
I'm also not entirely sure what the current code will do in the perfectly ordinary case of leap seconds. While our servers at Google have the luxury of having this discontinuity hidden from them, its not clear to me that every computer without a leap smear should be considered to be improperly keeping time.
I got tripped up here when I went looking for ways to implement the correct behavior on our various platforms. I wasn't able to find anything on Linux or Darwin, though I think I recall having found the right call on windows.
If we aren't going to fix it for the net deadlines, I don't think it can be called a fix.
I got tripped up here when I went looking for ways to implement the correct behavior on our various platforms. I wasn't able to find anything on Linux or Darwin, though I think I recall having found the right call on windows.
If we aren't going to fix it for the net deadlines, I don't think it can be called a fix.
It seems like there's consensus that at least time.Ticker and company should use a monotonic clock underneath. As for net.Conn.SetDeadline(), API disagreement aside (it's part of the contract - there's little point in debating it until Go 2), is there agreement that it would be good to translate values to a monotonic clock under the hood to preserve implied duration through clock jitter? Brad?
I think you're giving some special meaning to the absolute value ofOn Tue, Jan 14, 2014 at 11:51 AM, Russ Cox <r...@golang.org> wrote:
> I'll put it differently then.
>
> A proposal to improve the implementation that does not modify any existing
> APIs and that does not significantly complicate the implementation would be
> fine.
>
> Trying to model weird new clocks with API modifications is a waste of time.
>
> Russ
the system clock. Let's think about the following example. Some
country decides to restart their year count from 1. Instead of using
UTC, they set their system clocks to 0001-01-01. Once the timezone
database gets updated, is this going to be a problem for time.Time?
Will Go be able to figure out that 2014-01-14 for us is 0001-01-14 for
them?
If so, how is this situation different from obtaining one time.Time
instance from the system clock and another from the monotonic clock?
The monotonic clock may have started counting up from 0 when the
system booted. That's the same as the local time for the country
that's now counting years from 1. All you need is a Location that
specifies how to map from one to the other.
I think that even with one clock, a program that relies on such
comparisons is technically broken. Timezone information comes from a
database. Even for UTC you have leap seconds. Is there anything
stopping a Go program from updating its timezone database while it is
running? How about asking the OS to perform the conversion? How about
a program saving the output of t.In(tz) to a file, restarting, doing
the same calculation, and then comparing the result with the file
contents?
the system clock. Let's think about the following example. SomeI think you're giving some special meaning to the absolute value of
country decides to restart their year count from 1. Instead of using
UTC, they set their system clocks to 0001-01-01. Once the timezone
database gets updated, is this going to be a problem for time.Time?
Will Go be able to figure out that 2014-01-14 for us is 0001-01-14 for
them?