new thread •When the system is stressed – overhead of thread scheduling and context switching •The system waste resources for allocating threads instead of doing actual work
event loop must wait until it has finished to execute the next command. • Non-Blocking Function - • Main event loop will continue as soon as the function begins • Alerts the main loop once it has finished by calling a “callback”.
Blocking IO + Event Loop • Constant amount of threads • CPU Intensive operation will block the event loop • CPU intensive operation that will be off loaded to the worker thread pool will make one of the threads busy for long
add Libraries to Node core to enable threads • Adding threads will change the nature of JavaScript • No synchronise mechanism • JavaScript basic types are not atomic, for example numerics
provided by the parent worker • The worker runs in Isolation from other workers • Ability to pass messages between the worker and the parent • Parallelism - V8 Isolate
production - use worker threads pool • If you can - use asynchronous operations, it is much faster • Don’t use Worker Thread for IO operations - Node.js built in mechanisms are much faster