• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2          Copyright Oliver Kowalke 2016.
3 Distributed under the Boost Software License, Version 1.0.
4    (See accompanying file LICENSE_1_0.txt or copy at
5          http://www.boost.org/LICENSE_1_0.txt
6]
7
8[section:performance Performance]
9
10Performance measurements were taken using `std::chrono::highresolution_clock`,
11with overhead corrections.
12The code was compiled with gcc-6.3.1, using build options:
13variant = release, optimization = speed.
14Tests were executed on dual Intel XEON E5 2620v4 2.2GHz, 16C/32T, 64GB RAM,
15running Linux (x86_64).
16
17Measurements headed 1C/1T were run in a single-threaded process.
18
19The [@https://github.com/atemerev/skynet microbenchmark ['syknet]] from
20Alexander Temerev was ported and used for performance measurements.
21At the root the test spawns 10 threads-of-execution (ToE), e.g.
22actor/goroutine/fiber etc.. Each spawned ToE spawns additional 10 ToEs ...
23until *1,000,000* ToEs are created. ToEs return back their ordinal numbers
24(0 ... 999,999), which are summed on the previous level and sent back upstream,
25until reaching the root. The test was run 10-20 times, producing a range of
26values for each measurement.
27
28[table time per actor/erlang process/goroutine (other languages) (average over 1,000,000)
29    [
30         [Haskell | stack-1.4.0/ghc-8.0.1]
31         [Go | go1.8.1]
32         [Erlang | erts-8.3]
33    ]
34    [
35        [0.05 \u00b5s - 0.06 \u00b5s]
36        [0.42 \u00b5s - 0.49 \u00b5s]
37        [0.63 \u00b5s - 0.73 \u00b5s]
38    ]
39]
40
41Pthreads are created with a stack size of 8kB while `std::thread`'s use the
42system default (1MB - 2MB). The microbenchmark could *not* be *run* with 1,000,000
43threads because of *resource exhaustion* (pthread and std::thread).
44Instead the test runs only at *10,000* threads.
45
46[table time per thread (average over 10,000 - unable to spawn 1,000,000 threads)
47    [
48         [pthread]
49         [`std::thread`]
50         [`std::async`]
51    ]
52    [
53        [54 \u00b5s - 73 \u00b5s]
54        [52 \u00b5s - 73 \u00b5s]
55        [106 \u00b5s - 122 \u00b5s]
56    ]
57]
58
59The test utilizes 16 cores with Symmetric MultiThreading enabled (32 logical
60CPUs). The fiber stacks are allocated by __fixedsize_stack__.
61
62As the benchmark shows, the memory allocation algorithm is significant for
63performance in a multithreaded environment. The tests use glibc[s] memory
64allocation algorithm (based on ptmalloc2) as well as Google[s]
65[@http://goog-perftools.sourceforge.net/doc/tcmalloc.html TCmalloc] (via
66linkflags="-ltcmalloc").[footnote
67Tais B. Ferreira, Rivalino Matias, Autran Macedo, Lucio B. Araujo
68["An Experimental Study on Memory Allocators in Multicore and
69Multithreaded Applications], PDCAT [,]11 Proceedings of the 2011 12th
70International Conference on Parallel and Distributed Computing, Applications
71and Technologies, pages 92-98]
72
73In the __work_stealing__ scheduling algorithm, each thread has its own local
74queue. Fibers that are ready to run are pushed to and popped from the local
75queue. If the queue runs out of ready fibers, fibers are stolen from the local
76queues of other participating threads.
77
78[table time per fiber (average over 1.000.000)
79    [
80         [fiber (16C/32T, work stealing, tcmalloc)]
81         [fiber (1C/1T, round robin, tcmalloc)]
82    ]
83    [
84        [0.05 \u00b5s - 0.09 \u00b5s]
85        [1.69 \u00b5s - 1.79 \u00b5s]
86    ]
87]
88
89[endsect]
90