2

So, below is my understanding of node.js. Please correct me if I am missing anything here.

  • Each incoming request will be stored in an event queue first.

  • Event loop will be serving requests from event queue.

  • Non blocking request will be directly served through event loop without invoking threads.

  • Blocking requests will send the response to event pool post completion and event pool which in turn will send the requests back to the clients.

Lets consider internal thread pool has a size of x and we have y no of concurrent requests trying to access our application all are blocking I/O (y > x).

So, event loop will be processing these x number of requests through consuming x (which is the total number of threads as well) number of threads and as all x requests being blocking I/O, lets consider all are in processing state and none of them were completed.

  • Now, for the rest of the requests i.e (y-x) which are of blocking I/O, What will happen to them?
  • If they are going to be served post release of some of the threads, then what are the advantages of using node compared to multithreading provided by other languages?
  • Which one will be prioritized by event loop, serving requests from event queue or serving response from blocking I/O request (refer above info 4)
  • If event loop picks requests one by one from event queue and lets say that each request takes 10sec to complete and all are of non blocking nature and we have a total of 20 such requests which are queued in event queue, then in that case it will take event loop 190sec (completion time of 19 requests) to pick the 20th request and similarly it will take 180sec to pick the 19th request and so on. It, will be too much time consuming which should not be the case. How does node handle this case?
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
user
  • 31
  • 4

0 Answers0