![]() ![]() During this period, the application won’t execute any of the other tasks in the event loop including responding to requests from clients.Ī situation like that drastically reduces the performance of a Node application. The event loop then executes the callback function registered for the operation on its thread.īecause callbacks are run on the event loop, if any of them contains CPU-intensive operations such as complex mathematical calculations used in machine learning or big data, it blocks the event loop for a considerable time. A thread in the worker pool executes the task asynchronously and notifies the event loop once the operation is completed. The expensive operation is offloaded to a set of auxiliary threads called the worker pool. So instead of waiting for the expensive operation to complete, the event loop registers the callback function attached to the event and moves on to handle the next event in the loop. Node uses it to handle the following execution when an event is triggered.īut if the execution of the event is expensive, like in the case of CPU-bound and I/O bound tasks, Node can’t afford to run it on the event loop without holding up the only available thread for a long time. We call the single thread running in Node programs the event loop. Why Can’t Node Handle CPU Intensive Tasks? To understand why worker threads are important, however, let’s first discuss why exactly Node performs poorly when handling CPU-intensive tasks. So, in this tutorial, we are going to give you a simplified introduction to worker threads and how to use them. Worker threads provide a mechanism to spawn new threads to handle CPU-intensive tasks in a Node program. But it also makes Node an unsuitable choice for implementing CPU-intensive tasksīut as a workaround to this problem, in its v10.5.0 release, Node introduced the concept of worker threads. Often, we talk about how Node’s single-threaded nature makes Node applications easily scalable and resource-efficient. Sharing Memory Between Parent and Worker.Communication Between Parent and Worker Threads.Why Can’t Node Handle CPU Intensive Tasks?.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |