Isn't node.js IO native threaded?
Isn't node.js IO native threaded?
This is actually an important property of JavaScript that allows it to work without locks (as long as you do not await, your code runs completely synchronously and will not be interrupted). It's not a flaw, but definitely requires awareness.
Gevent code that doesn't spawn more than one native thread (the one that runs the event loop) also has this property - you don't need locks as long as you do not perform IO. In Python's case it can be more tricky, as you might end up yielding to the event loop by indirectly performing IO when logging or something similar.
In JavaScript, the only case, AFAIK, where this can happen is when you await. Nothing else will cause you to yield to the event loop.
[0] by "push tasks" I mean using setTimeout, new Promise(), await, requestAnimationFrame, or similar
Though I would say it doing any real compute work inline rather than farming it out to workers is a boneheaded idea regardless of the language used.
I can vaguely recall (but it's 1AM so I didn't verify - take with a grain of salt) that nodejs uses an a thread pool for IO, but I guess that's only for IO for which there is no async API, otherwise that would be wasteful.
I imagine a quick search about the event loop and said thread pool would yield better researched answers :)
async IO creates a thread servicing that IO request
Nope. The event is a single FIFO queue implemented with libuv. It differentiates between sync and async function and basically goes around the queue running synchronous functions to completion every time it find one and async ones for a set time before switching to next one.ps -eLf disagrees:
$ ps -eLf|grep node
deploynode 16438 16173 16438 0 11 00:21 pts/6 00:00:01 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16439 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16440 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16441 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16442 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16443 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16444 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16445 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16446 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16447 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16438 16173 16448 0 11 00:21 pts/6 00:00:00 /opt/bin/node node-le-manager-api 3550
deploynode 16579 8353 16579 0 1 00:27 pts/4 00:00:00 grep nodeChrome supports several different process models, apparently, but as Spectre/Meltdown (as well as future renderer and UXSS bugs) mitigation it now by default runs a minimum of one process per site/origin (site isolation). See https://www.chromium.org/developers/design-documents/process... and https://www.chromium.org/Home/chromium-security/site-isolati...
From a high level you can think of it as a single thread that can only context switch during an IO call. Otherwise the function has to run and block all the way to termination. <---- This is what rachel is complaining about.