Thomas Hunter II @tlhunter |
Bryan English @bengl |
(2021)
We work for Datadog. And we're hiring!
Concurrency | Parallelism |
Quick show of hands...
Which model is the JS Event Loop?
(Yes, we've heard these or variations on them fairly recently.)
[sad duck noises]
$ ps -M -p 12345 PID TT %CPU STAT PRI STIME UTIME COMMAND 40046 s005 0.0 S 31T 0:00.01 0:00.03 node hello.js 40046 0.0 S 31T 0:00.00 0:00.00 40046 0.0 S 31T 0:00.00 0:00.00 40046 0.0 S 31T 0:00.00 0:00.00 40046 0.0 S 31T 0:00.00 0:00.00 40046 0.0 S 31T 0:00.00 0:00.00 40046 0.0 S 31T 0:00.00 0:00.00
If these conditions haven't been met then you shouldn't use threads.
on('message')
/ postMessage()
new SharedArrayBuffer()
ArrayBuffer
, but...Atomics.*
Message Passing: Can be done entirely using the .on('message')
and .postMessage()
methods.
Shared Memory: Still requires message passing but then uses SharedArrayBuffer
and Atomics
.
Hybrid: Uses message passing for synchronization while sharing data using SharedArrayBuffer
.
postMessage()
and on('message')
SharedArrayBuffer
and Atomics.*
SharedArrayBuffer
postMessage()
for synchronizationcluster
SharedArrayBuffer
(s) + Atomics
We found a situation where an app ran fine in prod but it would lock up in staging. Staging only had 100 millicores per app while prod had multiple cores.
structuredClone
, JSON.stringify
, all slowTC39 Structs Proposal!
unsafe{}
block, lintingPresentation |
Code Samples |
Keep an eye out for Multithreaded JavaScript 2nd ed!