I have limited the size of the thread pool to 25.
process.env.UV_THREADPOOL_SIZE = 25;
How can one know that all the threads are exhausted at run time?
Is there any way to find that all the define threads are exhausted during a new request?
I'm using Native Abstractions for Node.js (NAN) to call C++ functions. For every request to C++ Nan::AsyncQueueWorker is created. Here I want to find if the thread limit is exhausted and then add a safety factor.
Node. js has two types of threads: one Event Loop and k Workers. The Event Loop is responsible for JavaScript callbacks and non-blocking I/O, and a Worker executes tasks corresponding to C++ code that completes an asynchronous request, including blocking I/O and CPU-intensive work.
While Node. js itself is multithreaded -- I/O and other such operations run from a thread pool -- JavaScript code executed by Node. js runs, for all practical purposes, in a single thread. This isn't a limitation of Node.
Node. js is a single-threaded language and uses the multiple threads in the background for certain tasks as I/O calls but it does not expose child threads to the developer. But node. js gives us ways to work around if we really need to do some work parallelly to our main single thread process.
Are you looking implementation in nan or js?
In Nan impl:
You have to do it manually. Maintain a map where key is int and value as workAsyn. Push at every call and delete when workAsyn complete. Do this for every request.
Compare the size of map with your thread limit defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With