Skip to content

Commit 97b632b

Browse files
committed
article work
1 parent 18462b8 commit 97b632b

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

docs/article/lawn.pdf

437 Bytes
Binary file not shown.

docs/article/lawn.tex

+25-28
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
\makesavenoteenv{tabular}
3838
\makesavenoteenv{table}
3939

40-
\title{Timer Lawn: Solving the Timer Wheel Overflow Problem Using Unbound Low Latency Timer Data Structure for Large Scale and High Throughput Systems}
40+
\title{Timer Lawn: Solving the Timer Wheel Overflow Problem for Large Scale and High Throughput Systems}
4141

4242

4343
\author{
@@ -102,26 +102,24 @@ \subsection{List and Tree Based Schemes}
102102

103103
\subsection{Hashed Timing Wheel}
104104
\complexity{Worst}{Mean}{n}{1}{n}{1}{1}{1}{the Hashed Timing Wheel scheme}
105-
The Hashed Timing Wheel was designed to be an all-purpose timer storage solution for a unified system of known size and resolution\cite{TW87, TW, TWI, largescale, autoscale}. While previous work has shown that Hashed Timing Wheels have optimal run-time complexity, and in ideal conditions are in fact, optimal, real-world implementations would suffer from either being bound by maximal TTL and resolution combination, or would require a costly ($O(n)$) run-time re-build upon of the data structure upon reaching such limits (in \cite{CQ} it is referred to as "the overflow problem"). For large numbers of timers, producers, or consumers as is common in large scale operations, the simplest and mose effective solution is to overestimate the needed resolution and/or TTL so to abstain from rebuilding for as long as possible.
105+
The Hashed Timing Wheel was designed to be an all-purpose timer storage solution for a unified system of known size and resolution\cite{TW87, TW, TWI, largescale, autoscale}. While previous work has shown that Hashed Timing Wheels have optimal run-time complexity, and in ideal conditions are in fact, optimal, real-world implementations would suffer from either being bound by maximal TTL and resolution combination, or would require a costly ($O(n)$) run-time re-build upon of the data structure upon reaching such limits (in \cite{CQ} it is referred to as "the overflow problem"). For large numbers of timers, producers, or consumers as is common in large scale operations, the simplest and mose effective solution is to overestimate the needed resolution and/or TTL so to abstain from rebuilding (resizing) for as long as possible.
106106

107107
\subsection{Overflow Algorithms}
108108
in order to handle overflows correctly there are two valid options:
109-
\subsubsection{increase current wheel slots (Alg. \ref{alg:overflow_rebuild})} Rebuild the overflowing wheel so it would include a larger number of slots into the future. This change entails a worst case cost of $O(n)$ upon any addition of an overflowing timer.
110-
\subsubsection{in place addition of cycle count for each item (Alg. \ref{alg:overflow_inplace})} Each element in a slot is also stored with the number of wheel cycles needed before element expiration. This change entails a worst case cost of $O(n)$ for all \textit{PerTickBookkeeping} operation.
111-
109+
\subsubsection{increase current wheel slots (Alg. \ref{alg:overflow_resize})} Resize the overflowing wheel so it would include a larger number of slots into the future. This change entails a worst case cost of $O(n)$ upon any addition of an overflowing timer.
112110

113111
\begin{algorithm}
114-
\caption{Timer Wheel Data Store Rebuild algorithm\label{alg:overflow_rebuild}}
112+
\caption{Timer Wheel Resize\label{alg:overflow_resize}}
115113
\begin{algorithmic}[1]
116114
\Function{StartTimer}{$id$, $ttl$, $payload$}
117115
\If{$ttl > len(Wheel)$}
118-
\Let{MissingSlots}{$ttl-len(Wheel)$}
119-
\Let{ExtWheel}{array of length $len(Wheel) + MissingSlots$}
120-
\For{Slot,SlotIndex \textbf{in} Wheel}
121-
\Let{NewSlotIndex}{(len(Wheel)+SlotIndex) $\textit{\textbf{mod}}$ len(ExtWheel) }
122-
\Let{ExtWheel[NewSlotIndex]}{Slot}
123-
\EndFor
124-
\Let{Wheel}{ExtWheel}
116+
\Let{MissingSlots}{$ttl-len(Wheel)$}
117+
\Let{ExtWheel}{array of length $len(Wheel) + MissingSlots$}
118+
\For{Slot,SlotIndex \textbf{in} Wheel}
119+
\Let{NewSlotIndex}{(len(Wheel)+SlotIndex) $\textit{\textbf{mod}}$ len(ExtWheel) }
120+
\Let{ExtWheel[NewSlotIndex]}{Slot}
121+
\EndFor
122+
\Let{Wheel}{ExtWheel}
125123
\EndIf
126124
\Let{$slot$}{(current time+ttl) \textit{\textbf{mod}} $len(Wheel)$}
127125
\State{append $payload$ to Wheel[$slot$]}
@@ -131,8 +129,10 @@ \subsubsection{in place addition of cycle count for each item (Alg. \ref{alg:ove
131129
\end{algorithm}
132130

133131

132+
\subsubsection{in place addition of cycle count for each item (Alg. \ref{alg:overflow_inplace})} Each element in a slot is also stored with the number of wheel cycles needed before element expiration. This change entails a worst case cost of $O(n)$ for all \textit{PerTickBookkeeping} operation.
133+
134134
\begin{algorithm}
135-
\caption{Timer Wheel Data Store Multipass (in-place) algorithm\label{alg:overflow_inplace}}
135+
\caption{Timer Wheel Multi-Pass (in-place)\label{alg:overflow_inplace}}
136136
\begin{algorithmic}[1]
137137
\Statex
138138
\Function{StartTimer}{$id$, $ttl$, $payload$}
@@ -154,8 +154,6 @@ \subsubsection{in place addition of cycle count for each item (Alg. \ref{alg:ove
154154
\end{algorithmic}
155155
\end{algorithm}
156156

157-
158-
159157
\section{The Lawn Data Structure}
160158

161159
\subsection{Intended Use Cases}
@@ -285,24 +283,23 @@ \section{Comparison and Reflection}
285283

286284
\begin{table}[ht]
287285
\begin{center}
288-
\begin{tabular}{l|c|c}
286+
\begin{tabular}{l|c|c|c}
289287
%& \multicolumn{2}{c}{\textbf{Case}} \\
290-
\textbf{Operation} & \textbf{Timing Wheel} & \textbf{Lawn} \\
288+
\textbf{Operation} & \textbf{TW (Resize)} & \textbf{TW (Multi-Pass)} & \textbf{Lawn} \\
291289
\hline
292-
\textit{StartTimer} & $O(1)$ & $O(1)$ \\
293-
\textit{StartTimer} & \boldmath{$O(n)$}\footnote{only if \textit{Rebuild} overflow handling algorithm is used, else O(1)} & $O(1)$ \\
294-
\textit{PerTick} & $O(1)$ & \boldmath{$O(t\sim1)$} \\
295-
\textit{DeleteTimer} & $O(1)$ & $O(1)$ \\
296-
\textit{TimerExpired} & \boldmath{$O(n)$}\footnote{only if \textit{Multipass} overflow handling algorithm is used, else O(1)} & $O(1)$ \\
297-
\textit{space} & $O(n)$ & $O(n)$ \\
290+
\textit{StartTimer} & \boldmath{$O(n)$}\footnote{\label{overflowfn}on overflow, else O(1)} & $O(1)$ & $O(1)$ \\
291+
\textit{PerTick} & $O(1)$ & $O(1)$ & \boldmath{$O(t\sim1)$} \\
292+
\textit{DeleteTimer} & $O(1)$ & $O(1)$ & $O(1)$ \\
293+
\textit{TimerExpired} & $O(1)$ & \boldmath{$O(n)$}\footnote{see footnote \ref{overflowfn}} & $O(1)$ \\
294+
\textit{space} & $O(n)$ & $O(n)$ & $O(n)$ \\
298295
\end{tabular}
299296
\linebreak
300-
\caption{Mean Runtime Complexity comparison}
297+
\caption{Runtime Complexity comparison}
301298
\end{center}
302299
\end{table}
303300

304301
\subsection{A View of Multiprocessing}
305-
Unlike the state-of-the-art Timer Wheel algorithm, Lawn enables the simultaneous timer handling and bookkeeping by splitting the buckets between several worker processes or threads, adding or removing workers as needed. This method enables usage of the Lawn algorithm in highly parallel applications and does not require the use of semaphores than other synchronization mechanisms within the bucket level.
302+
Unlike the state-of-the-art Timer Wheel algorithm, Lawn enables the simultaneous timer handling and bookkeeping by splitting the buckets between several worker processes, threads or even different machines altogether, adding or removing workers as needed. This method enables usage of the Lawn algorithm in large scale or highly parallel applications and does not require the use of semaphores than other synchronization mechanisms within a single bucket.
306303

307304

308305
\subsection{Known implementations of Lawn}
@@ -316,8 +313,8 @@ \subsection{Known implementations of Lawn}
316313
\end{enumerate}
317314

318315
\section{Conclusion}
319-
Lawn is a simplified overflow-free algorithm that displays near-optimal results for use cases involving many (millions) concurrent timers from large scale (tens of thousands) of independent machine systems.
320-
Using Lawn is an elegant solution to the overflow problem in Timer Wheel and other current algorithms, requiring less knowledge about the usage pattern with the only requirement is for the TTLs being discrete and bound, but not what the bounds are.
316+
Lawn is a simplified overflow-free algorithm that displays near-optimal results for use cases involving many (tens of millions) concurrent timers from large scale (tens of thousands) independent machine systems.
317+
Using Lawn is an elegant solution to the overflow problem in Timer Wheel and other current algorithms, enabling simpler use of available cores and requiring less knowledge about the usage pattern with the only requirement is for the TTLs being discrete and their number being bound, but not knowing what the bound on max TTL is.
321318
The algorithm is currently deployed and in use by several organizations under real-world load, all reporting satisfactory results.
322319

323320

0 commit comments

Comments
 (0)