How the node pool works

3

If, for the time being, my server does not receive many requests or is in development (only receives my test requests), does it make sense to decrease UV_THREADPOOL_SIZE ?

If my server is receiving many requests, is there any gain to increase UV_THREADPOOL_SIZE ?

In case of a server that has large and small processes

    
asked by anonymous 23.06.2018 / 19:15

1 answer

1

NodeJs Thread pool

Yes on NodeJs your code runs on only one thread, however this does not restrict the Node from creating new threads for certain operations, if needed.

The concept you have to understand is that NodeJS processes a list of events, this is known as event loop . A simple way to understand the event loop is for example on a HTTP server. When a HTTP request reaches your Node server a new item is inserted to process in the event list. And at some point Node will call the code that you have registered to handle this event.

Delayed operations can and should make use of the Node event loop. The purpose is that if an operation is too time-consuming, the event loop of the Node can continue running while this operation is processed.

When the operation completes it will log an event in the event loop and once again your code will run in the same thread as ever.

UV_THREADPOOL_SIZE

As a general rule, you should not change the default values specified by the platform.

Before changing any of these values in order to optimize performance you should be rigorous in your tests and use a profiler to see if you get any benefit.

SOEN - When is the thread pool used

    
02.07.2018 / 21:48