1

Let's say we have 3 request(A,B,C) hitting our node.js server at the same time.

What will be node.js criteria to identify which request should be executed first of all?

One more thing all request are blocking operations.

Alok Deshwal
  • 1,128
  • 9
  • 20

2 Answers2

1

AFAIK there is no such thing as exactly simultaneous requests - at least somewhere inside the network/transport layer the packets carrying those requests are serialized.

Which will make them reach the node server serialized as well. Their position in the request queue will reflect that serialization.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • May you please explain it step by step ? – Alok Deshwal Apr 11 '16 at 15:56
  • I think it should be related to HTTP protocol and TCP connection. Check this thread to see if you can get some ideas: http://stackoverflow.com/questions/16288102/is-it-possible-to-receive-out-of-order-responses-with-http – hankchiutw Apr 12 '16 at 16:27
  • 1
    @AlokDeshwal: I have a bit of a hard time making it simpler... in the vast majority of cases the network communications between 2 internet devices are serial: bit by bit, datagram after datagram, packet after packet. Even if the physical server has multiple interfaces each having its own incoming packet queue an application server running on it only has one incoming queue. From here Hank's answer is better. – Dan Cornilescu Apr 12 '16 at 17:07
1

You may want to learn about node.js event loop. Also, check Anatomy of an HTTP transaction.

hankchiutw
  • 1,546
  • 1
  • 12
  • 15
  • @AlokDeshwal: the key point related to your question is the message/request queue: requests are dequeued for processing one at a time, in their queue position order. – Dan Cornilescu Apr 12 '16 at 17:13