/
timing-wheels.tex
308 lines (255 loc) · 8.36 KB
/
timing-wheels.tex
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage{minted}
%%\usemintedstyle{perldoc}
\usetheme{default}
\beamertemplatenavigationsymbolsempty{}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,chains,arrows}
\title{Implementations of Timing Wheels}
\author{Julian Squires}
\institute{AdGear Technologies, Inc.}
\date{March 16, 2017}
\begin{document}
\begin{frame}
\titlepage{}
\end{frame}
\begin{frame}{Disclaimers}
\begin{itemize}
\item Performance claims without benchmarks are damned lies;
\item I don't understand all these systems;
\item I'm handwaving on many complex issues, especially concurrency
and multiprocessor issues;
\item 20 minutes is not enough time;
\item Time is the enemy.
\end{itemize}
\end{frame}
\begin{frame}
Varghese and Lauck. ``Hashed and hierarchical timing
wheels: Data structures for the efficient implementation of a timer
facility.'' ACM SIGOPS Operating Systems Review 21.5 (1987): 25--38.
\vspace{1.5em}
Varghese and Lauck. ``Hashed and hierarchical timing wheels: efficient
data structures for implementing a timer facility.'' IEEE/ACM
transactions on networking 5.6 (1997): 824--834.
\vspace{1.5em}
Varghese. Network Algorithmics: An Interdisciplinary Approach
To Designing Fast Networked Devices. Morgan Kaufmann, 2004.
\end{frame}
\begin{frame}{Recent activity}
\begin{itemize}
\item LWN on Gleixner's timing wheels patch:
\hyperlink{https://lwn.net/Articles/646950/}{https://lwn.net/Articles/646950/}
\item Adrian Colyer's Morning Paper blog:
\hyperlink{https://blog.acolyer.org/2015/11/23/hashed-and-hierarchical-timing-wheels/}{https://blog.acolyer.org/2015/11/23/hashed-and-hierarchical-timing-wheels/}
\item Juho Snellman on Ratas:
\hyperlink{https://www.snellman.net/blog/archive/2016-07-27-ratas-hierarchical-timer-wheel/}{https://www.snellman.net/blog/archive/2016-07-27-ratas-hierarchical-timer-wheel/}
\end{itemize}
\end{frame}
\begin{frame}{Timing facility users}
\begin{columns}[t]
\column{0.5\textwidth}\centering
Optimistic\\[.2cm]
\begin{itemize}
\item simulations
\item scheduling
\item flow control
\item circuit breakers
\item watchdogs
\end{itemize}
\column{0.5\textwidth}\centering
Pessimistic\\[.2cm]
\begin{itemize}
\item requests awaiting responses
\item TCP retransmit timers
\item I/O timeouts
\end{itemize}
\end{columns}
\end{frame}
\begin{frame}{Guarantees of a timer system}
A timer scheduled to fire after $t$ ticks will have its action
executed, some time after $t$ ticks (if your clock is monotonic and
doesn't jump forward or skew forward and \ldots)
\end{frame}
\begin{frame}{Design considerations}
\begin{itemize}
\item optimistic versus pessimistic
\item accuracy versus performance
\item ranged scheduling versus exact
\item periodic versus one-shot
\item throughput versus latency
\item bounded work per timer interrupt
\begin{itemize}
\item timer stampede
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Unordered lists}
\begin{center}
\includegraphics{unordered-list.eps}
\end{center}
\begin{itemize}
\item{Vixie cron}
\end{itemize}
\end{frame}
%%%% ORDERED LISTS
\begin{frame}{Ordered lists}
\begin{center}
\includegraphics{ordered-list.eps}
\end{center}
\begin{itemize}
\item Zephyr (\hyperlink{http://zephyrproject.org/}{http://zephyrproject.org/})
\begin{itemize}
\item \texttt{kernel/include/timeout\_q.h, kernel/timer.c}
\end{itemize}
\item XNU (Darwin/macOS) (\hyperlink{http://opensource.apple.com/}{http://opensource.apple.com/})
\begin{itemize}
\item \texttt{osfmk/kern/call\_entry.h, osfmk/kern/thread\_call.c, osfmk/kern/timer\_call.c}
\end{itemize}
\item pre-1997 Linux, *BSD
\end{itemize}
\end{frame}
%%%% BINARY HEAPS
\begin{frame}{Binary heaps}
\hfill \begin{tikzpicture}
[-,thick,%
every node/.style={shape=circle,inner sep=1.5pt,draw,thick},%
scale=0.5]
\footnotesize
\node {}
[sibling distance=4cm]
child {node {}
[sibling distance=2cm]
child {node {}
[sibling distance=1cm]
child {node[rectangle,inner sep=4pt,draw,thick] {}}
child {node[rectangle,inner sep=4pt,draw,thick] {}}
}
child {node {}
[sibling distance=1cm]
child {node[rectangle,inner sep=4pt,draw,thick] {}}
child {node[rectangle,inner sep=4pt,draw,thick] {}}
}
}
child {node {}
[sibling distance=2cm]
child {node {}
[sibling distance=1cm]
child {node[rectangle,inner sep=4pt,draw,thick] {}}
child {node[rectangle,inner sep=4pt,draw,thick] {}}
}
child {node {}
[sibling distance=1cm]
child {node[rectangle,inner sep=4pt,draw,thick] {}}
child {node[rectangle,inner sep=4pt,draw,thick] {}}
}
};
\end{tikzpicture}
\vspace{-2em} \begin{itemize}
\item libev (also a 4-heap!)
\item libuv
\begin{itemize}
\item \texttt{src/heap\_inl.h, src/unix/timer.c}
\end{itemize}
\item OpenJDK DelayQueue
\begin{itemize}
\item \texttt{src/java.base/share/classes /java/util/concurrent/DelayQueue.java}
\end{itemize}
\item Illumos
\begin{itemize}
\item \texttt{usr/src/uts/common/os/cyclic.c}
\item \texttt{usr/src/uts/common/os/callout.c}
\end{itemize}
\end{itemize}
\end{frame}
%%%% TIMING WHEELS
\begin{frame}{Timing wheels}
\begin{center}
\includegraphics{timing-wheel.eps}
\end{center}
\end{frame}
%%%% HIERARCHICAL TIMING WHEELS
\begin{frame}{Hierarchical timing wheels}
\begin{center}
\includegraphics[width=\textwidth]{hierarchical-timing-wheels.eps}
\end{center}
\end{frame}
\begin{frame}{Hierarchical timing wheels}
\begin{itemize}
\item Linux
\begin{itemize}
\item \texttt{linux/kernel/time/timer.c}
\end{itemize}
\item Ratas (\hyperlink{https://github.com/jsnell/ratas}{https://github.com/jsnell/ratas})
\item Kafka
\begin{itemize}
\item \texttt{core/src/main/scala/kafka/ utils/timer/TimingWheel.scala}
\end{itemize}
\item timeout (\hyperlink{https://github.com/wahern/timeout}{https://github.com/wahern/timeout})
\end{itemize}
\end{frame}
%%%% HASHED TIMING WHEELS
\begin{frame}{Hashed timing wheels}
\begin{itemize}
\item *BSD\
\begin{itemize}
\item \texttt{sys/kern/kern\_timeout.c}
\end{itemize}
\item Erlang (port and proc timers)
\begin{itemize}
\item \texttt{erts/emulator/beam/time.c}
\end{itemize}
\item Netty
\begin{itemize}
\item \texttt{common/src/main/java/io /netty/util/HashedWheelTimer.java}
\end{itemize}
\end{itemize}
\vspace{1.5em} Costello and Varghese. ``Redesigning the BSD callout
and timer facilities.'' (1995).
\vspace{1em} Italiano and Motin. ``Calloutng: a new infrastructure
for timer facilities in the FreeBSD kernel.'' (2013).
\end{frame}
%%%% OPTIONAL
\begin{frame}{Other techniques}
\begin{itemize}
\item calendar queues
\item skip lists
\begin{itemize}
\item DPDK (http://dpdk.org/)
(\texttt{lib/librte\_timer/rte\_timer.c})
\end{itemize}
\item red-black trees
\begin{itemize}
\item Linux (\texttt{kernel/time/hrtimer.c})
\item Erlang (\texttt{erts/emulator/beam/erl\_hl\_timer.c})
\end{itemize}
\item hash table
\begin{itemize}
\item node.js (\texttt{lib/timers.js})
\end{itemize}
\item softheaps?
\end{itemize}
\end{frame}
\begin{frame}{$O( lg N)$ versus $O(1)$}
Jason Evans says:
\begin{quotation}
In essence, my initial failure was to disregard the difference between
a O(1) algorithm and a O(lg n) algorithm. Intuitively, I think of
logarithmic-time algorithms as fast, but constant factors and large n
can conspire to make logarthmic time not nearly good enough.
\end{quotation}
\hyperlink{http://t-t-travails.blogspot.ca/2008/07/overzealous-use-of-my-red-black-tree.html}{http://t-t-travails.blogspot.ca/2008/07/overzealous-use-of-my-red-black-tree.html}
\end{frame}
\begin{frame}
\begin{center}
\includegraphics[width=0.5\textwidth]{logo_adgear_smaller.png}
\end{center}
\vspace{3em}
\begin{center}
Julian Squires \\
\hyperlink{mailto:julian@cipht.net}{$<$julian@cipht.net$>$}
\end{center}
\end{frame}
\end{document}