source: doc/theses/thierry_delisle_PhD/thesis/text/eval_micro.tex @ fcfbc52

ADTast-experimentalpthread-emulation
Last change on this file since fcfbc52 was e9e3d02, checked in by Peter A. Buhr <pabuhr@…>, 23 months ago

small changes to Churn

  • Property mode set to 100644
File size: 36.8 KB
Line 
1\chapter{Micro-Benchmarks}\label{microbench}
2
3The first step in evaluating this work is to test small controlled cases to ensure the basics work properly.
4This chapter presents five different experimental setups for evaluating the basic features of the \CFA, libfibre~\cite{libfibre}, Go, and Tokio~\cite{Tokio} schedulers.
5All of these systems have a \gls{uthrding} model.
6The goal in this chapter is show the \CFA scheduler obtains equivalent performance to other less fair schedulers through the different experiments.
7Note, only the code of the \CFA tests is shown;
8all tests in the other systems are functionally identical and available online~\cite{SchedulingBenchmarks}.
9
10\section{Benchmark Environment}\label{microenv}
11
12All benchmarks are run on two distinct hardware platforms.
13\begin{description}
14\item[AMD] is a server with two AMD EPYC 7662 CPUs and 256GB of DDR4 RAM.
15The EPYC CPU has 64 cores with 2 \glspl{hthrd} per core, for 128 \glspl{hthrd} per socket with 2 sockets for a total of 256 \glspl{hthrd}.
16Each CPU has 4 MB, 64 MB and 512 MB of L1, L2 and L3 caches, respectively.
17Each L1 and L2 instance are only shared by \glspl{hthrd} on a given core, but each L3 instance is shared by 4 cores, therefore 8 \glspl{hthrd}.
18The server runs Ubuntu 20.04.2 LTS on top of Linux Kernel 5.8.0-55.
19
20\item[Intel] is a server with four Intel Xeon Platinum 8160 CPUs and 384GB of DDR4 RAM.
21The Xeon CPU has 24 cores with 2 \glspl{hthrd} per core, for 48 \glspl{hthrd} per socket with 4 sockets for a total of 196 \glspl{hthrd}.
22Each CPU has 3 MB, 96 MB and 132 MB of L1, L2 and L3 caches respectively.
23Each L1 and L2 instance are only shared by \glspl{hthrd} on a given core, but each L3 instance is shared across the entire CPU, therefore 48 \glspl{hthrd}.
24The server runs Ubuntu 20.04.2 LTS on top of Linux Kernel 5.8.0-55.
25\end{description}
26
27For all benchmarks, @taskset@ is used to limit the experiment to 1 NUMA node with no hyper threading.
28If more \glspl{hthrd} are needed, then 1 NUMA node with hyperthreading is used.
29If still more \glspl{hthrd} are needed, then the experiment is limited to as few NUMA nodes as needed.
30For the Intel machine, this means that from 1 to 24 \procs one socket and \emph{no} hyperthreading is used, and from 25 to 48 \procs still only one socket is used but \emph{with} hyperthreading.
31This pattern is repeated between 49 and 96, between 97 and 144, and between 145 and 192.
32On AMD, the same algorithm is used, but the machine only has 2 sockets.
33So hyperthreading\footnote{
34Hyperthreading normally refers specifically to the technique used by Intel, however it is often used generically to refer to any equivalent feature.}
35is used when the \proc count reach 65 and 193.
36
37The limited sharing of the last-level cache on the AMD machine is markedly different than the Intel machine.
38Indeed, while on both architectures L2 cache misses that are served by L3 caches on a different CPU incur a significant latency, on the AMD it is also the case that cache misses served by a different L3 instance on the same CPU also incur high latency.
39
40\section{Experimental setup}
41
42Each experiment is run 15 times varying the number of processors depending on the two different computers.
43All experiments gather throughput data and secondary data for scalability or latency.
44The data is graphed using a solid and two dashed lines representing the median, maximum and minimum result respectively, where the minimum/maximum lines are referred to as the \emph{extremes}.\footnote{
45An alternative display is to use error bars with min/max as the bottom/top for the bar.
46However, this approach is not truly an error bar around a mean value and I felt the connected lines are easier to read.}
47This graph presentation offers an overview of the distribution of the results for each experiment.
48
49For each experiment, four graphs are generated showing traditional throughput on the top row and \newterm{scalability} or \newterm{latency} on the bottom row (peek ahead to Figure~\ref{fig:cycle:jax}).
50Scalability uses the same data as throughput but the Y axis is calculated as the number of \procs over the throughput.
51In this representation, perfect scalability should appear as a horizontal line, \eg, if doubling the number of \procs doubles the throughput, then the relation stays the same.
52
53The left column shows results for 100 cycles per \proc, enough cycles to always keep every \proc busy.
54The right column shows results for 1 cycle per \proc, where the ready queues are expected to be near empty most of the time.
55The distinction between 100 and 1 cycles is meaningful because the idle sleep subsystem is expected to matter only in the right column, where spurious effects can cause a \proc to run out of work temporarily.
56
57\section{Cycle}
58
59The most basic evaluation of any ready queue is the latency needed to push and pop one element from the ready queue.
60Since these two operations also describe a @yield@ operation, many systems use this operation as the fundamental benchmark.
61However, yielding can be treated as a special case by optimizing it away since the number of ready \ats does not change.
62Hence, systems that perform this optimization have an artificial performance benefit because the yield becomes a \emph{nop}.
63For this reason, I designed a different push/pop benchmark, called \newterm{Cycle Benchmark}.
64This benchmark arranges a number of \ats into a ring, as seen in Figure~\ref{fig:cycle}, where the ring is a circular singly-linked list.
65At runtime, each \at unparks the next \at before parking itself.
66Unparking the next \at pushes that \at onto the ready queue while the ensuing park leads to a \at being popped from the ready queue.
67
68\begin{figure}
69        \centering
70        \input{cycle.pstex_t}
71        \caption[Cycle benchmark]{Cycle benchmark\smallskip\newline Each \at unparks the next \at in the cycle before parking itself.}
72        \label{fig:cycle}
73\end{figure}
74
75Therefore, the underlying runtime cannot rely on the number of ready \ats staying constant over the duration of the experiment.
76In fact, the total number of \ats waiting on the ready queue is expected to vary because of the race between the next \at unparking and the current \at parking.
77That is, the runtime cannot anticipate that the current task immediately parks.
78As well, the size of the cycle is also decided based on this race, \eg a small cycle may see the chain of unparks go full circle before the first \at parks because of time-slicing or multiple \procs.
79If this happens, the scheduler push and pop are avoided and the results of the experiment are skewed.
80(Note, an unpark is like a V on a semaphore, so the subsequent park (P) may not block.)
81Every runtime system must handle this race and cannot optimized away the ready-queue pushes and pops.
82To prevent any attempt of silently omitting ready-queue operations, the ring of \ats is made big enough so the \ats have time to fully park before being unparked again.
83Finally, to further mitigate any underlying push/pop optimizations, especially on SMP machines, multiple rings are created in the experiment.
84
85Figure~\ref{fig:cycle:code} shows the pseudo code for this benchmark, where each cycle has 5 \ats.
86There is additional complexity to handle termination (not shown), which requires a binary semaphore or a channel instead of raw @park@/@unpark@ and carefully picking the order of the @P@ and @V@ with respect to the loop condition.
87
88\begin{figure}
89\begin{cfa}
90Thread.main() {
91        count := 0
92        for {
93                @this.next.wake()@
94                @wait()@
95                count ++
96                if must_stop() { break }
97        }
98        global.count += count
99}
100\end{cfa}
101\caption[Cycle Benchmark : Pseudo Code]{Cycle Benchmark : Pseudo Code}
102\label{fig:cycle:code}
103%\end{figure}
104
105\bigskip
106
107%\begin{figure}
108        \subfloat[][Throughput, 100 cycles per \proc]{
109                \resizebox{0.5\linewidth}{!}{
110                        \input{result.cycle.jax.ops.pstex_t}
111                }
112                \label{fig:cycle:jax:ops}
113        }
114        \subfloat[][Throughput, 1 cycle per \proc]{
115                \resizebox{0.5\linewidth}{!}{
116                        \input{result.cycle.low.jax.ops.pstex_t}
117                }
118                \label{fig:cycle:jax:low:ops}
119        }
120
121        \subfloat[][Scalability, 100 cycles per \proc]{
122                \resizebox{0.5\linewidth}{!}{
123                        \input{result.cycle.jax.ns.pstex_t}
124                }
125                \label{fig:cycle:jax:ns}
126        }
127        \subfloat[][Scalability, 1 cycle per \proc]{
128                \resizebox{0.5\linewidth}{!}{
129                        \input{result.cycle.low.jax.ns.pstex_t}
130                }
131                \label{fig:cycle:jax:low:ns}
132        }
133        \caption[Cycle Benchmark on Intel]{Cycle Benchmark on Intel\smallskip\newline Throughput and scalability as a function of \proc count, 5 \ats per cycle, and different cycle count. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are maximums while the solid line is the medium.}
134        \label{fig:cycle:jax}
135\end{figure}
136
137\begin{figure}
138        \subfloat[][Throughput, 100 cycles per \proc]{
139                \resizebox{0.5\linewidth}{!}{
140                        \input{result.cycle.nasus.ops.pstex_t}
141                }
142                \label{fig:cycle:nasus:ops}
143        }
144        \subfloat[][Throughput, 1 cycle per \proc]{
145                \resizebox{0.5\linewidth}{!}{
146                        \input{result.cycle.low.nasus.ops.pstex_t}
147                }
148                \label{fig:cycle:nasus:low:ops}
149        }
150
151        \subfloat[][Scalability, 100 cycles per \proc]{
152                \resizebox{0.5\linewidth}{!}{
153                        \input{result.cycle.nasus.ns.pstex_t}
154                }
155                \label{fig:cycle:nasus:ns}
156        }
157        \subfloat[][Scalability, 1 cycle per \proc]{
158                \resizebox{0.5\linewidth}{!}{
159                        \input{result.cycle.low.nasus.ns.pstex_t}
160                }
161                \label{fig:cycle:nasus:low:ns}
162        }
163        \caption[Cycle Benchmark on AMD]{Cycle Benchmark on AMD\smallskip\newline Throughput and scalability as a function of \proc count, 5 \ats per cycle, and different cycle count. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
164        \label{fig:cycle:nasus}
165\end{figure}
166
167\subsection{Results}
168
169For the Intel architecture, Figure~\ref{fig:cycle:jax}:
170\begin{itemize}
171\item
172For 100 cycles per \proc (first column), \CFA, Go and Tokio all obtain effectively the same throughput performance.
173Libfibre is slightly behind in this case but still scales decently.
174As a result of the \gls{kthrd} placement, additional \procs from 25 to 48 offer less performance improvement (flatting of the line) for all runtimes.
175As expected, this pattern repeats again between \proc count 72 and 96.
176\item
177For 1 cycle per \proc, \CFA and Tokio obtain very similar results overall, but Tokio shows more variations in the results.
178Go achieves slightly better performance.
179Interestingly, libfibre achieves better performance with 1 cycle.
180\end{itemize}
181
182For the AMD architecture, Figure~\ref{fig:cycle:nasus}, the results show the same story as on the Intel, with close to double the performance overall but with slightly increased variation.
183The different performance improvements and plateaus are due to cache topology and appear at the expected \proc counts of 64, 128 and 192, for the same reasons as on Intel.
184\begin{itemize}
185\item
186For 100 cycles per \proc, unlike Intel, all 4 runtimes achieve very similar throughput and scalability.
187\item
188For 1 cycle per \proc, unlike on Intel, Tokio and Go have the same throughput performance, while \CFA is slightly slower.
189Again, the same performance increase for libfibre is visible.
190\end{itemize}
191Note, I did not investigate the libfibre performance boost for 1 cycle in this experiment.
192
193The conclusion from both architectures is that all of the compared runtime have fairly equivalent performance for this micro-benchmark.
194Clearly, the pathological case with 1 \at per \proc, can affect fairness algorithms managing mostly idle processors, \eg \CFA, but only at high core counts.
195For this case, \emph{any} helping is likely to cause a cascade of \procs running out of work and attempting to steal.
196For this experiment, the \CFA scheduler has achieved the goal of obtaining equivalent performance to other less fair schedulers, except for very unusual workloads.
197
198\section{Yield}
199
200For completion, the classic yield benchmark is included.
201Here, the throughput is dominated by the mechanism used to handle the @yield@ function.
202Figure~\ref{fig:yield:code} shows pseudo code for this benchmark, where the cycle @wait/next.wake@ is replaced by @yield@.
203As mentioned, this benchmark may not be representative because of optimization shortcuts in @yield@.
204The only interesting variable in this benchmark is the number of \ats per \procs, where ratios close to 1 means the ready queue(s) can be empty, which again puts a strain on the idle-sleep handling.
205
206\begin{figure}
207\begin{cfa}
208Thread.main() {
209        count := 0
210        for {
211                @yield()@
212                count ++
213                if must_stop() { break }
214        }
215        global.count += count
216}
217\end{cfa}
218\caption[Yield Benchmark : Pseudo Code]{Yield Benchmark : Pseudo Code}
219\label{fig:yield:code}
220%\end{figure}
221\bigskip
222%\begin{figure}
223        \subfloat[][Throughput, 100 \ats per \proc]{
224                \resizebox{0.5\linewidth}{!}{
225                        \input{result.yield.jax.ops.pstex_t}
226                }
227                \label{fig:yield:jax:ops}
228        }
229        \subfloat[][Throughput, 1 \ats per \proc]{
230                \resizebox{0.5\linewidth}{!}{
231                \input{result.yield.low.jax.ops.pstex_t}
232                }
233                \label{fig:yield:jax:low:ops}
234        }
235
236        \subfloat[][Scalability, 100 \ats per \proc]{
237                \resizebox{0.5\linewidth}{!}{
238                \input{result.yield.jax.ns.pstex_t}
239                }
240                \label{fig:yield:jax:ns}
241        }
242        \subfloat[][Scalability, 1 \ats per \proc]{
243                \resizebox{0.5\linewidth}{!}{
244                \input{result.yield.low.jax.ns.pstex_t}
245                }
246                \label{fig:yield:jax:low:ns}
247        }
248        \caption[Yield Benchmark on Intel]{Yield Benchmark on Intel\smallskip\newline Throughput and scalability as a function of \proc count, using 1 \ats per \proc. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
249        \label{fig:yield:jax}
250\end{figure}
251
252\subsection{Results}
253
254Figures~\ref{fig:yield:jax} and~\ref{fig:yield:nasus} show the same throughput graphs as @cycle@ on Intel and AMD, respectively.
255Note, the Y-axis on the yield graph for Intel is twice as large as the Intel cycle-graph.
256A visual glance between the cycle and yield graphs confirms my claim that the yield benchmark is unreliable.
257
258For the Intel architecture, Figure~\ref{fig:yield:jax}:
259\begin{itemize}
260\item
261\CFA has no special handling for @yield@, but this experiment requires less synchronization than the @cycle@ experiment.
262Hence, the @yield@ throughput and scalability graphs for both 100 and 1 cycles/tasks per processor have similar shapes to the corresponding @cycle@ graphs.
263The only difference is sightly better performance for @yield@ because of less synchronization.
264As for @cycle@, the cost of idle sleep also comes into play in a very significant way in Figure~\ref{fig:yield:jax:low:ns}, where the scaling is not flat.
265\item
266libfibre has special handling for @yield@ using the fact that the number of ready fibres does not change, and therefore, by-passing the idle-sleep mechanism entirely.
267Additionally, when only running 1 \at per \proc, libfibre optimizes further, and forgoes the context-switch entirely.
268Hence, libfibre behaves very differently in the cycle and yield benchmarks, with a 4 times increase in performance for 100 cycles/tasks and an 8 times increase for 1 cycle/task.
269\item
270Go has special handling for @yield@ by putting a yielding goroutine on a secondary global ready-queue, giving it lower priority.
271The result is that multiple \glspl{hthrd} contend for the global queue and performance suffers drastically.
272Hence, Go behaves very differently in the cycle and yield benchmarks, with a complete performance collapse in @yield@ for both 100 and 1 cycles/tasks.
273\item
274Tokio has a similar performance collapse after 16 processors, and therefore, its special @yield@ handling is probably related to a Go-like scheduler problem and/or a \CFA idle-sleep problem.
275(I did not dig through the Rust code to ascertain the exact reason for the collapse.)
276\end{itemize}
277
278\begin{figure}
279        \subfloat[][Throughput, 100 \ats per \proc]{
280                \resizebox{0.5\linewidth}{!}{
281                        \input{result.yield.nasus.ops.pstex_t}
282                }
283                \label{fig:yield:nasus:ops}
284        }
285        \subfloat[][Throughput, 1 \at per \proc]{
286                \resizebox{0.5\linewidth}{!}{
287                        \input{result.yield.low.nasus.ops.pstex_t}
288                }
289                \label{fig:yield:nasus:low:ops}
290        }
291
292        \subfloat[][Scalability, 100 \ats per \proc]{
293                \resizebox{0.5\linewidth}{!}{
294                        \input{result.yield.nasus.ns.pstex_t}
295                }
296                \label{fig:yield:nasus:ns}
297        }
298        \subfloat[][Scalability, 1 \at per \proc]{
299                \resizebox{0.5\linewidth}{!}{
300                        \input{result.yield.low.nasus.ns.pstex_t}
301                }
302                \label{fig:yield:nasus:low:ns}
303        }
304        \caption[Yield Benchmark on AMD]{Yield Benchmark on AMD\smallskip\newline Throughput and scalability as a function of \proc count, using 1 \ats per \proc. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
305        \label{fig:yield:nasus}
306\end{figure}
307
308For the AMD architecture, Figure~\ref{fig:yield:nasus}, the results show the same story as on the Intel, with slightly increased variations.
309Also, some transition points on the X-axis differ because of the architectures, like at 16 versus 24 processors.
310
311It is difficult to draw conclusions for this benchmark when runtime system treat @yield@ so differently.
312The win for \CFA is its consistency between the cycle and yield benchmarks making it simpler for programmers to use and understand, \ie the \CFA semantics match with programmer intuition.
313
314
315\section{Churn}
316
317The Cycle and Yield benchmark represent an \emph{easy} scenario for a scheduler, \eg an embarrassingly parallel application.
318In these benchmarks, \ats can be easily partitioned over the different \procs upfront and none of the \ats communicate with each other.
319
320The Churn benchmark represents more chaotic executions, where there is more communication among \ats but no relationship between the last \proc on which a \at ran and blocked and the \proc that subsequently unblocks it.
321With processor-specific ready-queues, when a \at is unblocked by a different \proc that means the unblocking \proc must either ``steal'' the \at from another processor or find it on a remote queue.
322This dequeuing results in either contention on the remote queue and/or \glspl{rmr} on the \at data structure.
323Hence, this benchmark has performance dominated by the cache traffic as \proc are constantly accessing the each other's data.
324In either case, this benchmark aims to measure how well a scheduler handles these cases, since both cases can lead to performance degradation if not handled correctly.
325
326This benchmark uses a fixed-size array of counting semaphores.
327Each \at picks a random semaphore, @V@s it to unblock any waiting \at, and then @P@s (maybe blocks) the \ats on the semaphore.
328This creates a flow where \ats push each other out of the semaphores before being pushed out themselves.
329For this benchmark to work, the number of \ats must be equal or greater than the number of semaphores plus the number of \procs;
330\eg if there are 10 semaphores and 5 \procs, but only 3 \ats, all 3 \ats can block (P) on a random semaphore and now there is no \ats to unblock (V) them.
331Note, the nature of these semaphores mean the counter can go beyond 1, which can lead to nonblocking calls to @P@.
332Figure~\ref{fig:churn:code} shows pseudo code for this benchmark, where the @yield@ is replaced by @V@ and @P@.
333
334\begin{figure}
335\begin{cfa}
336Thread.main() {
337        count := 0
338        for {
339                r := random() % len(spots)
340                @spots[r].V()@
341                @spots[r].P()@
342                count ++
343                if must_stop() { break }
344        }
345        global.count += count
346}
347\end{cfa}
348\caption[Churn Benchmark : Pseudo Code]{Churn Benchmark : Pseudo Code}
349\label{fig:churn:code}
350%\end{figure}
351\bigskip
352%\begin{figure}
353        \subfloat[][Throughput, 100 \ats per \proc]{
354                \resizebox{0.5\linewidth}{!}{
355                        \input{result.churn.jax.ops.pstex_t}
356                }
357                \label{fig:churn:jax:ops}
358        }
359        \subfloat[][Throughput, 2 \ats per \proc]{
360                \resizebox{0.5\linewidth}{!}{
361                        \input{result.churn.low.jax.ops.pstex_t}
362                }
363                \label{fig:churn:jax:low:ops}
364        }
365
366        \subfloat[][Latency, 100 \ats per \proc]{
367                \resizebox{0.5\linewidth}{!}{
368                        \input{result.churn.jax.ns.pstex_t}
369                }
370                \label{fig:churn:jax:ns}
371        }
372        \subfloat[][Latency, 2 \ats per \proc]{
373                \resizebox{0.5\linewidth}{!}{
374                        \input{result.churn.low.jax.ns.pstex_t}
375                }
376                \label{fig:churn:jax:low:ns}
377        }
378        \caption[Churn Benchmark on Intel]{\centering Churn Benchmark on Intel\smallskip\newline Throughput and latency of the Churn on the benchmark on the Intel machine. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
379        \label{fig:churn:jax}
380\end{figure}
381
382\subsection{Results}
383
384Figures~\ref{fig:churn:jax} and Figure~\ref{fig:churn:nasus} show the throughput on Intel and AMD respectively.
385
386The performance cost of crossing the cache boundaries is still visible at the same \proc count.
387
388Scalability is notably worst than the previous benchmarks since there is inherently more communication between processors.
389Indeed, once the number of \glspl{hthrd} goes beyond a single socket, performance ceases to improve.
390An interesting aspect to note here is that the runtimes differ in how they handle this situation.
391Indeed, when a \proc unparks a \at that was last run on a different \proc, the \at could be appended to the ready-queue local \proc or to the ready-queue of the remote \proc, which previously ran the \at.
392\CFA, Tokio and Go all use the approach of unparking to the local \proc while Libfibre unparks to the remote \proc.
393In this particular benchmark, the inherent chaos of the benchmark in addition to small memory footprint means neither approach wins over the other.
394
395\begin{figure}
396        \subfloat[][Throughput, 100 \ats per \proc]{
397                \resizebox{0.5\linewidth}{!}{
398                        \input{result.churn.nasus.ops.pstex_t}
399                }
400                \label{fig:churn:nasus:ops}
401        }
402        \subfloat[][Throughput, 2 \ats per \proc]{
403                \resizebox{0.5\linewidth}{!}{
404                        \input{result.churn.low.nasus.ops.pstex_t}
405                }
406                \label{fig:churn:nasus:low:ops}
407        }
408
409        \subfloat[][Latency, 100 \ats per \proc]{
410                \resizebox{0.5\linewidth}{!}{
411                        \input{result.churn.nasus.ns.pstex_t}
412                }
413                \label{fig:churn:nasus:ns}
414        }
415        \subfloat[][Latency, 2 \ats per \proc]{
416                \resizebox{0.5\linewidth}{!}{
417                        \input{result.churn.low.nasus.ns.pstex_t}
418                }
419                \label{fig:churn:nasus:low:ns}
420        }
421        \caption[Churn Benchmark on AMD]{\centering Churn Benchmark on AMD\smallskip\newline Throughput and latency of the Churn on the benchmark on the AMD machine.
422        For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
423        \label{fig:churn:nasus}
424\end{figure}
425
426Like for the cycle benchmark, here all runtimes achieve fairly similar performance.
427Performance improves as long as all \procs fit on a single socket.
428Beyond that performance starts to suffer from increased caching costs.
429
430Indeed on Figures~\ref{fig:churn:jax:ops} and \ref{fig:churn:jax:ns} show that with 1 and 100 \ats per \proc, \CFA, libfibre, Go and Tokio achieve effectively equivalent performance for most \proc count.
431
432However, Figure~\ref{fig:churn:nasus} again shows a somewhat different story on AMD.
433While \CFA, libfibre, and Tokio achieve effectively equivalent performance for most \proc count, Go starts with better scaling at very low \proc counts but then performance quickly plateaus, resulting in worse performance at higher \proc counts.
434This performance difference is visible at both high and low \at counts.
435
436One possible explanation for this difference is that since Go has very few available concurrent primitives, a channel was used instead of a semaphore.
437On paper a semaphore can be replaced by a channel and with zero-sized objects passed along equivalent performance could be expected.
438However, in practice there can be implementation difference between the two.
439This is especially true if the semaphore count can get somewhat high.
440Note that this replacement is also made in the cycle benchmark, however in that context it did not seem to have a notable impact.
441
442As second possible explanation is that Go may sometimes use the heap when allocating variables based on the result of escape analysis of the code.
443It is possible that variables that should be placed on the stack are placed on the heap.
444This could cause extra pointer chasing in the benchmark, heightening locality effects.
445Depending on how the heap is structure, this could also lead to false sharing.
446
447The objective of this benchmark is to demonstrate that unparking \ats from remote \procs do not cause too much contention on the local queues.
448Indeed, the fact all runtimes achieve some scaling at lower \proc count demonstrate that migrations do not need to be serialized.
449Again these result demonstrate \CFA achieves satisfactory performance.
450
451\section{Locality}
452
453\begin{figure}
454\newsavebox{\myboxA}
455\newsavebox{\myboxB}
456
457\begin{lrbox}{\myboxA}
458\begin{cfa}[tabsize=3]
459Thread.main() {
460        count := 0
461        for {
462                r := random() % len(spots)
463                // go through the array
464                @work( a )@
465
466                spots[r].V()
467                spots[r].P()
468                count ++
469                if must_stop() { break }
470        }
471        global.count += count
472}
473\end{cfa}
474\end{lrbox}
475
476\begin{lrbox}{\myboxB}
477\begin{cfa}[tabsize=3]
478Thread.main() {
479        count := 0
480        for {
481                r := random() % len(spots)
482                // go through the array
483                @work( a )@
484                // pass array to next thread
485                spots[r].V( @a@ )
486                @a = @spots[r].P()
487                count ++
488                if must_stop() { break }
489        }
490        global.count += count
491}
492\end{cfa}
493\end{lrbox}
494
495\subfloat[Thread$_1$]{\label{f:CFibonacci}\usebox\myboxA}
496\hspace{3pt}
497\vrule
498\hspace{3pt}
499\subfloat[Thread$_2$]{\label{f:CFAFibonacciGen}\usebox\myboxB}
500
501\caption[Locality Benchmark : Pseudo Code]{Locality Benchmark : Pseudo Code}
502\label{fig:locality:code}
503\end{figure}
504
505As mentioned in the churn benchmark, when unparking a \at, it is possible to either unpark to the local or remote ready-queue.
506\footnote{It is also possible to unpark to a third unrelated ready-queue, but without additional knowledge about the situation, there is little to suggest this would not degrade performance.}
507The locality experiment includes two variations of the churn benchmark, where an array of data is added.
508In both variations, before @V@ing the semaphore, each \at increment random cells inside the array.
509The @share@ variation then passes the array to the shadow-queue of the semaphore, transferring ownership of the array to the woken thread.
510In the @noshare@ variation the array is not passed on and each thread continuously accesses its private array.
511
512The objective here is to highlight the different decision made by the runtime when unparking.
513Since each thread unparks a random semaphore, it means that it is unlikely that a \at will be unparked from the last \proc it ran on.
514In the @share@ version, this means that unparking the \at on the local \proc is appropriate since the data was last modified on that \proc.
515In the @noshare@ version, the unparking the \at on the remote \proc is the appropriate approach.
516
517The expectation for this benchmark is to see a performance inversion, where runtimes will fare notably better in the variation which matches their unparking policy.
518This should lead to \CFA, Go and Tokio achieving better performance in @share@ while libfibre achieves better performance in @noshare@.
519Indeed, \CFA, Go and Tokio have the default policy of unpark \ats on the local \proc, where as libfibre has the default policy of unparks \ats wherever they last ran.
520
521\subsection{Results}
522
523\begin{figure}
524        \subfloat[][Throughput share]{
525                \resizebox{0.5\linewidth}{!}{
526                        \input{result.locality.share.jax.ops.pstex_t}
527                }
528                \label{fig:locality:jax:share:ops}
529        }
530        \subfloat[][Throughput noshare]{
531                \resizebox{0.5\linewidth}{!}{
532                        \input{result.locality.noshare.jax.ops.pstex_t}
533                }
534                \label{fig:locality:jax:noshare:ops}
535        }
536
537        \subfloat[][Scalability share]{
538                \resizebox{0.5\linewidth}{!}{
539                        \input{result.locality.share.jax.ns.pstex_t}
540                }
541                \label{fig:locality:jax:share:ns}
542        }
543        \subfloat[][Scalability noshare]{
544                \resizebox{0.5\linewidth}{!}{
545                        \input{result.locality.noshare.jax.ns.pstex_t}
546                }
547                \label{fig:locality:jax:noshare:ns}
548        }
549        \caption[Locality Benchmark on Intel]{Locality Benchmark on Intel\smallskip\newline Throughput and scalability as a function of \proc count. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
550        \label{fig:locality:jax}
551\end{figure}
552\begin{figure}
553        \subfloat[][Throughput share]{
554                \resizebox{0.5\linewidth}{!}{
555                        \input{result.locality.share.nasus.ops.pstex_t}
556                }
557                \label{fig:locality:nasus:share:ops}
558        }
559        \subfloat[][Throughput noshare]{
560                \resizebox{0.5\linewidth}{!}{
561                        \input{result.locality.noshare.nasus.ops.pstex_t}
562                }
563                \label{fig:locality:nasus:noshare:ops}
564        }
565
566        \subfloat[][Scalability share]{
567                \resizebox{0.5\linewidth}{!}{
568                        \input{result.locality.share.nasus.ns.pstex_t}
569                }
570                \label{fig:locality:nasus:share:ns}
571        }
572        \subfloat[][Scalability noshare]{
573                \resizebox{0.5\linewidth}{!}{
574                        \input{result.locality.noshare.nasus.ns.pstex_t}
575                }
576                \label{fig:locality:nasus:noshare:ns}
577        }
578        \caption[Locality Benchmark on AMD]{Locality Benchmark on AMD\smallskip\newline Throughput and scalability as a function of \proc count. For throughput, higher is better, for scalability, lower is better. Each series represent 15 independent runs, the dotted lines are extremes while the solid line is the medium.}
579        \label{fig:locality:nasus}
580\end{figure}
581
582Figures~\ref{fig:locality:jax} and \ref{fig:locality:nasus} shows the results on Intel and AMD respectively.
583In both cases, the graphs on the left column show the results for the @share@ variation and the graphs on the right column show the results for the @noshare@.
584
585On Intel, Figure~\ref{fig:locality:jax} shows Go trailing behind the 3 other runtimes.
586On the left of the figure showing the results for the shared variation, where \CFA and Tokio slightly outperform libfibre as expected.
587And correspondingly on the right, we see the expected performance inversion where libfibre now outperforms \CFA and Tokio.
588Otherwise the results are similar to the churn benchmark, with lower throughput due to the array processing.
589Presumably the reason why Go trails behind are the same as in Figure~\ref{fig:churn:nasus}.
590
591Figure~\ref{fig:locality:nasus} shows the same experiment on AMD.
592\todo{why is cfa slower?}
593Again, we see the same story, where Tokio and libfibre swap places and Go trails behind.
594
595\section{Transfer}
596The last benchmark is more of an experiment than a benchmark.
597It tests the behaviour of the schedulers for a misbehaved workload.
598In this workload, one of the \at is selected at random to be the leader.
599The leader then spins in a tight loop until it has observed that all other \ats have acknowledged its leadership.
600The leader \at then picks a new \at to be the next leader and the cycle repeats.
601The benchmark comes in two flavours for the non-leader \ats:
602once they acknowledged the leader, they either block on a semaphore or spin yielding.
603
604The experiment is designed to evaluate the short-term load-balancing of a scheduler.
605Indeed, schedulers where the runnable \ats are partitioned on the \procs may need to balance the \ats for this experiment to terminate.
606This problem occurs because the spinning \at is effectively preventing the \proc from running any other \at.
607In the semaphore flavour, the number of runnable \ats eventually dwindles down to only the leader.
608This scenario is a simpler case to handle for schedulers since \procs eventually run out of work.
609In the yielding flavour, the number of runnable \ats stays constant.
610This scenario is a harder case to handle because corrective measures must be taken even when work is available.
611Note, runtime systems with preemption circumvent this problem by forcing the spinner to yield.
612
613In both flavours, the experiment effectively measures how long it takes for all \ats to run once after a given synchronization point.
614In an ideal scenario where the scheduler is strictly FIFO, every thread would run once after the synchronization and therefore the delay between leaders would be given by:
615$ \frac{CSL + SL}{NP - 1}$, where $CSL$ is the context switch latency, $SL$ is the cost for enqueueing and dequeuing a \at and $NP$ is the number of \procs.
616However, if the scheduler allows \ats to run many times before other \ats are able to run once, this delay will increase.
617The semaphore version is an approximation of the strictly FIFO scheduling, where none of the \ats \emph{attempt} to run more than once.
618The benchmark effectively provides the fairness guarantee in this case.
619In the yielding version however, the benchmark provides no such guarantee, which means the scheduler has full responsibility and any unfairness will be measurable.
620
621While this is a fairly artificial scenario, it requires only a few simple pieces.
622The yielding version of this simply creates a scenario where a \at runs uninterrupted in a saturated system, and starvation has an easily measured impact.
623However, \emph{any} \at that runs uninterrupted for a significant period of time in a saturated system could lead to this kind of starvation.
624
625\begin{figure}
626\begin{cfa}
627Thread.lead() {
628        this.idx_seen = ++lead_idx
629        if lead_idx > stop_idx {
630                done := true
631                return
632        }
633        // Wait for everyone to acknowledge my leadership
634        start: = timeNow()
635        for t in threads {
636                while t.idx_seen != lead_idx {
637                        asm pause
638                        if (timeNow() - start) > 5 seconds { error() }
639                }
640        }
641        // pick next leader
642        leader := threads[ prng() % len(threads) ]
643        // wake every one
644        if ! exhaust {
645                for t in threads {
646                        if t != me { t.wake() }
647                }
648        }
649}
650Thread.wait() {
651        this.idx_seen := lead_idx
652        if exhaust { wait() }
653        else { yield() }
654}
655Thread.main() {
656        while !done  {
657                if leader == me { this.lead() }
658                else { this.wait() }
659        }
660}
661\end{cfa}
662\caption[Transfer Benchmark : Pseudo Code]{Transfer Benchmark : Pseudo Code}
663\label{fig:transfer:code}
664\end{figure}
665
666\subsection{Results}
667\begin{figure}
668\begin{centering}
669\begin{tabular}{r | c c c c | c c c c }
670Machine   &                     \multicolumn{4}{c |}{Intel}                &          \multicolumn{4}{c}{AMD}                    \\
671Variation & \multicolumn{2}{c}{Park} & \multicolumn{2}{c |}{Yield} & \multicolumn{2}{c}{Park} & \multicolumn{2}{c}{Yield} \\
672\procs    &      2      &      192   &      2      &      192      &      2      &      256   &      2      &      256    \\
673\hline
674\CFA      & 106 $\mu$& ~19.9 ms   & 68.4 $\mu$s & ~1.2 ms       & 174 $\mu$& ~28.4 ms   & 78.8~~$\mu$s& ~~1.21 ms   \\
675libfibre  & 127 $\mu$& ~33.5 ms   & DNC         & DNC           & 156 $\mu$& ~36.7 ms   & DNC         & DNC         \\
676Go        & 106 $\mu$& ~64.0 ms   & 24.6 ms     & 74.3 ms       & 271 $\mu$& 121.6 ms   & ~~1.21~ms   & 117.4 ms    \\
677Tokio     & 289 $\mu$& 180.6 ms   & DNC         & DNC           & 157 $\mu$& 111.0 ms   & DNC         & DNC
678\end{tabular}
679\end{centering}
680\caption[Transfer Benchmark on Intel and AMD]{Transfer Benchmark on Intel and AMD\smallskip\newline Average measurement of how long it takes for all \ats to acknowledge the leader \at. DNC stands for ``did not complete'', meaning that after 5 seconds of a new leader being decided, some \ats still had not acknowledged the new leader.}
681\label{fig:transfer:res}
682\end{figure}
683
684Figure~\ref{fig:transfer:res} shows the result for the transfer benchmark with 2 \procs and all \procs, where each experiment runs 100 \at per \proc.
685Note that the results here are only meaningful as a coarse measurement of fairness, beyond which small cost differences in the runtime and concurrent primitives begin to matter.
686As such, data points that are the on the same order of magnitude as each other should be basically considered equal.
687The takeaway of this experiment is the presence of very large differences.
688The semaphore variation is denoted ``Park'', where the number of \ats dwindles down as the new leader is acknowledged.
689The yielding variation is denoted ``Yield''.
690The experiment was only run for the extremes of the number of cores since the scaling per core behaves like previous experiments.
691This experiments clearly demonstrate that while the other runtimes achieve similar performance in previous benchmarks, here \CFA achieves significantly better fairness.
692The semaphore variation serves as a control group, where all runtimes are expected to transfer leadership fairly quickly.
693Since \ats block after acknowledging the leader, this experiment effectively measures how quickly \procs can steal \ats from the \proc running leader.
694Figure~\ref{fig:transfer:res} shows that while Go and Tokio are slower, all runtime achieve decent latency.
695However, the yielding variation shows an entirely different picture.
696Since libfibre and Tokio have a traditional work-stealing scheduler, \procs that have \ats on their local queues will never steal from other \procs.
697The result is that the experiment simply does not complete for these runtime.
698Without \procs stealing from the \proc running the leader, the experiment will simply never terminate.
699Go manages to complete the experiment because it adds preemption on top of classic work-stealing.
700However, since preemption is fairly costly it achieves significantly worst performance.
701In contrast, \CFA achieves equivalent performance in both variations, demonstrating very good fairness.
702Interestingly \CFA achieves better delays in the yielding version than the semaphore version, however, that is likely due to fairness being equivalent but removing the cost of the semaphores and idle-sleep.
Note: See TracBrowser for help on using the repository browser.