Last active
June 21, 2019 01:09
-
-
Save enqtran/a1fd7638aa6388bb056c6e8fe1a40749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When a Node.js process is launched, it runs: | |
One process | |
One thread | |
One event loop | |
One JS Engine Instance | |
One Node.js Instance | |
One process: a process is a global object that can be accessed anywhere and has information about what’s being executed at a time. | |
One thread: being single-threaded means that only one set of instructions is executed at a time in a given process. | |
One event loop: this is one of the most important aspects to understand about Node. It’s what allows Node to be asynchronous and have non-blocking I/O, — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible through callbacks, promises and async/await. | |
One JS Engine Instance: this is a computer program that executes JavaScript code. | |
One Node.js Instance: the computer program that executes Node.js code. | |
The best solution: | |
The best solution for CPU performance is Worker Threads. Browsers have had the concept of Workers for a long time. | |
Instead of having: | |
One process | |
One thread | |
One event loop | |
One JS Engine Instance | |
One Node.js Instance | |
Worker threads have: | |
One process | |
Multiple threads | |
One event loop per thread | |
One JS Engine Instance per thread | |
One Node.js Instance per thread | |
[worker-diagram](https://images.ctfassets.net/hspc7zpa5cvq/20h5efXHT4bQbuf44mdq2H/a40944191d031217a9169b17a8ef35d6/worker-diagram_2x__1_.jpg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment