[CONCURRENT REQUEST]

98 views
Skip to first unread message

FleetCommand

unread,
Apr 9, 2012, 5:02:12 AM4/9/12
to nod...@googlegroups.com
Hi all ,

I would like to know , how node.js handles if two requests come in parallel.
For example : first a  dynamic http request comes wich requires some processing.
 suppose node.js is fetching parameters from request body and performing some validations,
 At the same time if a new request comoes (it can either be static file serving request or dynamic).
  So how node.js will handle this situation.

TIA,
Amit

Nikhil Marathe

unread,
Apr 9, 2012, 5:06:33 AM4/9/12
to nod...@googlegroups.com

Amit,

Each request is still coming on a different TCP socket, for all
purposes two different channels.
Each of these sockets has it's own object in the JS environment as
well (the argument to the tcp/http
server callback). read() is done on a socket, so the two requests data
will not overlap.

Nikhil

greelgorke

unread,
Dec 12, 2012, 4:29:21 AM12/12/12
to nod...@googlegroups.com
requests are always coming on the same socket. After the TSP-Handshake server opens a new socket for the connection to the client and handles the requests over it. the socket on bound on listen-port is still there for accepting connections. OS buffers incomming requests on this socket internaly in a queue. node handles this situation in the same way as other systems do: it accepts (or rejects) the connection opens a new socket for the client-connection and calls your callback passing the connection-object. the only difference in node is, that instead of spawning new threads it emits 'connection' events and the triggering of the connection-handler-function is handled by the event-loop.

Am Mittwoch, 12. Dezember 2012 10:12:51 UTC+1 schrieb Hardik Shah:
Hi Nikhil,
Thanks for the knowledge sharing...
As you are saying that each request is coming on different TCP socket, then again number of socket is limited (2^16=65536 - 1024 some reserved sockets)  so as per theory it can handle at max 64k concurrent request? is it like that? 
Thanks in advance.

greelgorke

unread,
Dec 12, 2012, 4:30:55 AM12/12/12
to nod...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages