On Fri, Dec 14, 2012 at 11:20 PM, Jonathon Morgan
<jonathonmor...@gmail.com> wrote:
> We make a high volume of requests over http between components in our
> system, and running into what seems to be a connection pooling issue that's
> difficult to track down.
>
> As far as I can tell, connection pools in Node are managed by a globalAgent
> (global to the Node process). The underlying TCP connections are established
> by the net module, which is used by the http module. I would expect that as
> soon as each request is resolved, the TCP connection that handled the
> request is available and can be reused.
>
> Instead however, the request handled by each connection up to the max # of
> connections (set on globalAgent.maxSockets) is resolved before any queued
> requests are handled.
>
> So if we set maxSockets to 10, we see 10 requests resolve successfully. Then
> there is a pause, while new tcp connections are established. Then 10 more
> requests resolve. Then a pause while connections are closed/re-established.
> Etc.
>
> This feels wrong. Node is supposed to excel at handling a high volume of
> concurrent requests. If request 1000 cannot be handled until 1-999 resolve,
> everyone who has ever used Node for anything would run into this bottleneck.
> Yet I can't work out what we're doing incorrectly.
>
> Any suggestions?
>
> Thanks!

http.Agent (of which http.globalAgent is an instance) reuses the
connection iff a new request is pending when the current request
finishes.  The requests need to overlap; if there is a time gap
between the old and the new request, the connection is closed.

This behavior is intentional: keeping idle connections open is
considered bad Internet citizenship.  But if you wish to override it,
you can, by implementing your own Agent class.

Of course, it's possible that the server is forcing the connection to
close, either explicitly by setting a "Connection: close" header, or
implicitly by omitting Content-Length and Transfer-Encoding headers,
returning a HTTP/1.0 response without a Keep-Alive header, etc.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to