/
worker-threads-lightning.html
124 lines (117 loc) · 4.96 KB
/
worker-threads-lightning.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Worker Threads</title>
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/black.css" id="theme">
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css" id="highlight-theme">
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-background-image="https://media.giphy.com/media/CKlafeh1NAxz35KTq4/giphy.gif">
<h1>Worker threads in Node.js</h1>
<aside class="notes">
This is adapted from a longer talk I gave at my previous company.
I've mainly skipped a whole lot of background and am focusing mainly on demos.
But there's a chance this means I've skipped some key stuff, so please interrupt and ask questions if something doesn't make sense!
</aside>
</section>
<section>
<img src="https://media.giphy.com/media/Nx85vtTY70T3W/giphy.gif"/>
<aside class="notes">
Note: Multithreaded Node.js is a misnomer really.
JS is single threaded.
This talk will be about some ways you can write JS to use multiple threads.
And a bit about why you might want to.
Focusing mainly on worker threads.
This is the new and recommended way to do it.
I went to a remote Node conference back in Nov and everyone was talking about worker threads.
Which I hadn't heard of at the time, so did some investigation.
I am by no means an expert, but I will share what I know!
</aside>
</section>
<section data-markdown="worker-threads/lightning/event-loop.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section data-markdown="worker-threads/lightning/options.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section data-markdown="worker-threads/lightning/enter-worker-threads.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section>
<h2>An example</h2>
<aside class="notes">
Code on https://github.com/rnewstead1/workers
</aside>
</section>
<section>
<img src="https://images.zenhubusercontent.com/570533156caf56c9d38f6ac7/217e1167-9f6e-4041-beb2-c6d4fd470c54"/>
</section>
<section data-markdown="worker-threads/lightning/caveats.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section data-markdown="worker-threads/lightning/real-life.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section>
<blockquote>Is Node.js the right language to use
if you're doing lots of CPU intensive work?</blockquote>
<aside class="notes">
Most of the cases where I have used Node it is for simple applications that don't need multithreading.
For example we use Node to build APIs that proxy graphql requests.
Get some data, transform it, make a request, transform the response, return it.
The thing that is likely to be slow there is the http layer.
Worker threads feel like a feature that's been added to try to keep people using Node.
To give it more feature parity with other languages.
Most of the time in your node applications, the bottlenecks are not down to the CPU, they are down to the overall architecture of networking and dbs.
I would love to hear if anyone has used this feature, or knows of it being used.
For me this was fun to learn about a new feature of a language.
But I can't see myself using it any time soon.
</aside>
</section>
<section data-background-image="https://media.giphy.com/media/5IT69msgpaOcg/giphy.gif"></section>
<section data-markdown="worker-threads/slides/further-reading.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
// Learn about plugins: https://revealjs.com/plugins/
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
});
</script>
</body>
</html>