-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Agent never establishes connections simultaneously #877
Comments
Me too. Why is this a feature and not a bug? Particularly since there is a cached agent per host:port anyways. |
You should understand async I/O. Node works fine 100 concurrent connections.
|
Koichik, The problem is not a misunderstanding of async I/O. The problem is that when you're trying to spam a server with many simultaneous http requests, the http Agent doesn't let you do it. That's because of the way the agent processes requests. When you make 100 http.get calls to the same server, the Agent queues all of those requests. Then it takes the first request and starts connecting. While it's waiting for a connection to the server, all 99 other requests are waiting in the queue. Once the first connection occurs, that transaction will do its thing and the second queued get will start connecting. Now you have one transacting connection, one pending connection, and 98 requests waiting in the queue. When the time it takes to do the transaction outweighs the time it takes to connect, the Agent will never reach the maxSockets. There is a way around this, by setting the { agent: false } in the http.connect options. Doing that does away with the inconvenience of the agent. But it seems the agent is supposed to do something important involving governing the flood of http requests. So yannooo's solution seems reasonable although I don't fully understand the full ramifications of that change. Chris |
Thanks, Christopher. Okay, I understand. |
Just renamed the issue title to your proposition. It is more accurate. |
I'm hitting this (or something with the same symptoms) with v0.4.8. I'm trying to write an HTTP load generator in node. The "agent: false" workaround works, as does setting the "connection: keep-alive" header with each request. |
After reading lots of post, I find out:
If I set it to "Connection":"close", the response time would be 100 times slower. Funny things happened here:
My guess is connection pooling still in effect even you set agent:false. However, if you keep connection:keep-alive, then it will be fast for sure. just don't switch it. |
Additional: for httpfix, it works. However, compare to just keep-alive, it is slower. e.g. around 200ms call. while doing keep-alive requires 60ms. However, when I look into keep-alive log, actually, it takes a longer time (200-300 ms) in the very beginning then speed up to 60ms. httpfix is steadily 190-200ms. In addition, i find out with both approach, if I run a 100concurrent x 100 loop test, it usually fails the call at 9000 something andn waiting for some callbacks. If one wait, the subsequent response will be on hold. |
In addition: |
Replace `==` with `===` and `assert.strictEqual()` in test-regress-nodejsGH-877.js. PR-URL: nodejs/node#8098 Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Replace `==` with `===` and `assert.strictEqual()` in test-regress-nodejsGH-877.js. PR-URL: nodejs/node#8098 Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Replace `==` with `===` and `assert.strictEqual()` in test-regress-nodejsGH-877.js. PR-URL: nodejs/node#8098 Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com> Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
I was trying to open 100 concurrent connections to an http server by setting
the agent maxSockets property to 100. During my tests I was unable to open more
than 10 concurrent connections to the server.
Looking at the agent's code in the _cycle method I discovered the agent won't open
a new connection if it can find a connecting socket. I believe this is wrong because
it won't try to establish multiple connections in parallel.
By removing this line in the _cycle command, new connection will be established even
if one is pending.
if (socket._httpConnecting) haveConnectingSocket = true;
I've made a small node program that shows that no more than one socket will be created if I create an http server that don't respond to http requests.
https://gist.github.com/903338
I'm using latest node version v0.4.5
Let me know if you need anything else.
The text was updated successfully, but these errors were encountered: