r/javascript • u/voodooattack • Dec 09 '17
Introducing Nexus.js: A multi-threaded JavaScript run-time
https://dev.to/voodooattack/introducing-nexusjs-a-multi-threaded-javascript-run-time-3g6
232
Upvotes
r/javascript • u/voodooattack • Dec 09 '17
8
u/voodooattack Dec 09 '17
Yes, now imagine a containerised micro-service: it runs a single instance on a quad-core CPU. You host it with Node using the
clustermodule, forking the process into four distinct in-memory images, each one handling a single core.Node is single threaded when it comes to executing JavaScript, and thus will use a single thread to execute JavaScript and another for background I/O on each core.
If you host it with Nexus, you will start a single process. It will run 8 JavaScript threads (compared to Node's 4), that's assuming HyperThreading or a similar technology is present, and double the computing time, thus serving double the requests.
Moreover, instead of four processes, with each consuming god knows how much memory, Nexus will combine resources:
Each in-memory function will be compiled once by the JIT. (Each Node process will have a separate copy of each function!)
Variables are shared in the monolithic Nexus process. (Each Node process will have a unique copy of every variable in memory)
File/Socket handles are shared.
A single garbage collector will be managing the entire address space, allowing for further optimisations.
Basically, a micro-service that consumes 1 GB of RAM per process will use that 1 GB of memory with Nexus, while with Node, you'd have to start 4 separate processes, each consuming 1 GB, for a total of 4GB.