-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotime.slide
137 lines (85 loc) · 3.23 KB
/
gotime.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Go time
Monotonic clocks in go land
Golang Paris Go 1.8 Release Party
16 February 2017
Anisse Astier
Independent Embedded Linux kernel engineer
anisse@astier.eu
https://plus.google.com/+AnisseA
* Time travel
: Came home from a night with some friends, and I was feeling hungry; so I decided to cook something. I had this nice frozen plate of pasta that said 30min in the over on the box. I think, cool! I have stuff to do anyway, so I'll put that in the oven and then wait for it be ready. It's now 2:45 am, I'll just watch for the clock until it's 3:15am, no big deal. So I go play some Rocket League, and it turns out the servers are quite full at this time of the night. I play a few games, and watch the time on my TV, and suddenly it's 2:20am. Wait, what? Did I just travel back in time ? Have one drink too many? I check my other watch, same time. I check my phone, same. And then it hits me. We're Sunday October 30th, and it's 2:20am it's daylight saving time.
: So what should I have done instead of using fixed time to measure intervals? Simply use the timer on my oven. That's the same with computers.
* Different times
.image img/wallclock.jpg _ 500
: When you want to know what time it is, you use this thing. It's wall clock
* Different times
.image img/stopwatch.png 500 _
: And if you're measuring intevals, you use a different tool: a time, a stopwatch, etc.
* Different times
- Wall clock
.image img/wallclock.jpg _ 200
- Monotonic clock
.image img/stopwatch.png 200 _
* Time jumps
- Timezone change (laptop, mobile phone)
- DST change
- NTP adjustments
- Leap seconds
: first two can be ignored with UTC
: NTP adjustments use adjtime() and can be monotonic
: man 3 adjtime
: only leap seconds are "real jumps"
* Time warp
Leap smear: [[https://developers.google.com/time/smear]]
* Go time
* Go time
time.Now()
Returns wall clock
.play timenow.go /time.Now/,/time.Now/
* Elapsed time
.play gotime.go /example1/,/Elapsed/
* Elapsed time
.code gotime.go /example2/,/Elapsed/
--> this is bad code!
Result:
Elapsed -989.12989ms
* Behind the times
: Most languages have a way to get monotonic clocks
C/C++
man 2 clock_gettime
CLOCK_REALTIME/CLOCK_MONOTONIC
Java
System.nanoTime
Python
time.monotnic
* Once upon a time
- Google as initial target
- Leap smear is a solved problem… right?
- Monotonic fixes throughout the library
Internal function:
runtime.nanotime
- Go 1 Compatibilty promise
* All in good time
* All in good time
A fix has been merged for Go 1.9
It changes the internal representation of time.Time
* All in good time
The fix does not add new API functions.
But it does change the behaviour of:
time.Since(t)
time.Until(t) // New in Go 1.8 !
t.Sub(u)
t.Before(u)
Which are now "correct".
* All in good time
.code gotime.go /time.Now/,/Elapsed/
--> this is now good code in Go 1.9+!
* The test of time
Slides for this talk: [[http://anisse.github.io/gotime]]
References:
- [[https://blog.cloudflare.com/how-and-why-the-leap-second-affected-cloudflare-dns/][Cloudflare leap second blog post]]
- [[https://github.com/golang/go/issues/12914][Go bug]]
- [[https://golang.org/design/12914-monotonic][Design document of the fix]]: this is the primary source for this talk
: Unused puns:
: * Time leap
: * Time out