-2

i remember the default thread pool size for node is 4 (or based on cpu count). This brings my question like this.

For the very basic simplified case, i'm writing a service1 in node, which sends requests to service2, wait till it finishes the computation and then continue. Now service2 in another server can handle 1000 requests at the same time, it takes time, also it's a blocking call (which is out of my control).

If i do the java way, i can create 1000 threads from glassfish, so the 1st 1000 blast requests can be processed at the same time. The 1001th may need to wait a little bit.

1000 incoming req -> java server1 -> 1000 threads -> 1000 outgoing req -> server2

But in node, if the thread pool size is 4 given it's a 4 core CPU machine, that means node app will be slower than java in this case ? What happens if i increase the pool size to 1000 ? Can i increase to 1000 ?

1000 incoming req -> node server1 -> ~4 threads -> 1000 outgoing req -> server2

I don't see an easy for node, or i can let node handle most stuff, for the above blocking call, add a small java server and dispatch outing req to that ? Any suggestion ?

UPDATE: found this, We use setTimeout( function(){} , 0 ); to create asynchronous functions in JavaScript! https://medium.com/from-the-scratch/javascript-writing-your-own-non-blocking-asynchronous-functions-60091ceacc79 Guess if i convert the block call into async function, it can solve my issue, i hope, praying !!!

user3552178
  • 2,719
  • 8
  • 40
  • 67
  • 1
    Possible duplicate of [How, in general, does Node.js handle 10,000 concurrent requests?](https://stackoverflow.com/questions/34855352/how-in-general-does-node-js-handle-10-000-concurrent-requests) – Sam Curry Apr 19 '19 at 20:10

1 Answers1

0

Node hands it's I/O tasks off to the operating system to handle, which are generally multi-threaded. It takes the approach of not having to wait for requests to finish (by blocking a thread), because it wastes time sitting. So, Node hands these tasks off and just tells it to poke Node when it's done. There is a very good related question.

How, in general, does Node.js handle 10,000 concurrent requests?

Sam Curry
  • 445
  • 2
  • 11