3

I want to implement the below thing using node js.

  1. Multiple thread handling parallel incoming REST calls
  2. An internal blocking queue(as in java) to block the requests beyond the size of the Queue until queue size goes below its maximum.
    • this is a similar implementation as of blocking queue as of Java

Could anyone please suggest how this can be implemented in node js.

vinit saha
  • 47
  • 3
  • 1
    I strongly suggest you keep the default single thread implementation instead of starting a worker for each request or use a worker pool unless you are doing CPU intensive stuff inside node itself like encoding mp3 or video using javascript etc. It is very unlikely that you will gain any extra performance from a multi-threaded implementation or you will need to be careful about it to not be slower than the optimized single threaded node.js – slebetman Oct 21 '20 at 02:34
  • See: https://stackoverflow.com/questions/34855352/how-in-general-does-node-js-handle-10-000-concurrent-requests/34857298#34857298 – slebetman Oct 21 '20 at 02:35
  • @slebetman Yes as the node code is not CPU intensive, I am using the default single thread implementation. But the thing is that in node js I invoke a exec command which forks a native process. I want to limit the number of exec to be called. Basically I want N number of exec to be called and all other call to exec to be blocked until the native process goes below N. This is very easy in Java using blocking queue not sure what to do in node js. I am new to node js . Please help – vinit saha Oct 21 '20 at 02:42
  • [Bluebird](http://bluebirdjs.com/docs/api-reference.html) provides some promise primitives with concurrency options, like [`.map()`](http://bluebirdjs.com/docs/api/promise.map.html) to do the "blocking" queue. – Matt Oct 21 '20 at 02:54

0 Answers0