Understanding Event Loops and Worker Pools
Why we need this?
Event-loop is an algrithm to retrive event handlers from Event queue.
When to use?
When program are io-bound process, and there has a non-blocking version of IO operates(eg, epoll),
Node.js uses the Worker Pool to handle “expensive” tasks. This includes I/O for which an operating system does not provide a non-blocking version, as well as particularly CPU-intensive tasks.
Combined with worker
How many workers to create?
- for cpu-bound task, it’s 1:1 more worker not helps since the CPU is the bottleneck.
- for io-bound task, it’s 1:many more worker can handle leverage more cpus, since the cpus are waiting for io for most of the time.
References
The reactor pattern web app apis, event-loops wiki event-loop