loading...

re: Is Node.js really single-threaded? VIEW POST

FULL DISCUSSION
 

So does this mean that there's no advantage in running Node on a super beefy 16 core machine?

 

It's a practice to spawn multiple instances of the app with this type of setup.
Have a look at cluster module.

nodejs.org/api/cluster.html

 

To get started with multiple instances, have a look at pm2. You can spawn as many instances as your cpu cores.

pm2.keymetrics.io/

 

Also check nodejs.org/api/worker_threads.html and threads.js.org/
You can truly have multiple threads now in Node. Handling Race condition is on you though, for now atleast. Best use case for workers is for logging and I/O operations.

 

Honestly, if you're looking to make use of heavy multithreading; Javascript just isn't the language you should be looking at I'm fraid

 

Unless you use threads.js

From what I can tell (correct me if I'm wrong), this uses service workers under the hood.
Those have the problem that you're not able to share memory, so if you want to pass large amounts of data around, you're effectively copying it every time it moves between threads.
While perhaps not problematic for some, I see this cause problems on large scale if you're not careful about what you're passing around; as well as the issue that suddenly you're not passing by reference whereas a regular function call would (for objects etc).

Code of Conduct Report abuse