Issue with HTTP module handling connections sequentially instead of concurrently

124 views
Skip to first unread message

beatgammit

unread,
Jul 26, 2011, 6:50:17 PM7/26/11
to nodejs
I have created an issue on node's github, and I was wondering if
anyone has seen this same bug and if there are any workarounds.

Please see the issue for the code I'm running on my server:

https://github.com/joyent/node/issues/1404

What's happening is that I have a basic server that has a setTimeout
for a second before it responds to the request. This is all working as
I expect. When I have multiple connections to the server, it seems to
be waiting for the response to be ended before it runs the next
connection.

Say I have 5 clients. The server should respond to each one after a
second. I set up a basic long-poll in a browser. Each client I started
caused the server to wait an additional second before it responded.
After adding all 5 clients, the server took 5 seconds to respond to
each client.

These clients are all running on my machine in the same browser, but
it appears to be making separate connections for each tab.

Is this a known bug? Am I not understanding something correctly?

C M

unread,
Jul 26, 2011, 8:06:05 PM7/26/11
to nod...@googlegroups.com
Have you tried using something like curl?  Browsers often 'pipeline' requests, and cannot necessarily be relied upon for multiple-request testing.  In other words, 5 tabs open to your site does not necessarily result in 5 concurrent requests.

--
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 nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Mark Hahn

unread,
Jul 26, 2011, 10:50:37 PM7/26/11
to nod...@googlegroups.com
Browsers used to be limited to a total of two open tcpip connections to any one server, based on early web specs.  There were "speed-up" hacks that increased the number.  However I think that all modern browsers ignore this and allow more.  I could be wrong.

Branko Vukelić

unread,
Jul 27, 2011, 3:46:52 AM7/27/11
to nod...@googlegroups.com
On 2011-07-26 15:50 -0700, beatgammit wrote:
> Say I have 5 clients. The server should respond to each one after a
> second. I set up a basic long-poll in a browser. Each client I started
> caused the server to wait an additional second before it responded.
> After adding all 5 clients, the server took 5 seconds to respond to
> each client.

You might want to try apache's ``ab`` utility to test this. For example,
using this simple server:

var http = require('http');
http.createServer(function (req, res) {
setInterval(function() {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}, 1000);
}).listen(3000, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3000/');

and hitting it with:

ab -n 10 -c 10 http://127.0.0.1:3000/

the requests take about 1 second to execute, and the average time for
each request is around 1000 milliseconds. (Incidentally, -n 10 and -c 10
means total 10 requests with concurrency of 10, which would give you 10
requests initiated at the same time, so it should take exactly 1 second
to respond to _all_ 10 requests.)

For comparison, the average times for:

10 concurrent requests: 1s/req
100 concurrent requests: 1.05 s/req
1000 concurrent requests: 1.1 s/req

All pretty close to parallel, wouldn't you say?

--
Branko Vukelic
bra...@herdhound.com
bg.b...@gmail.com

Lead Developer
Herd Hound (tm) - Travel that doesn't bite
www.herdhound.com

Love coffee? You might love Loveffee, too.
loveffee.appspot.com

Nicolas Chambrier

unread,
Jul 27, 2011, 3:49:25 AM7/27/11
to nod...@googlegroups.com
Just made the test, and I confirm it's running in parallel even in "real" browsers. I made a timeout of 5 seconds (so it's really visible) and reloaded the page in Opera + Firefox + Chrome + Chromium and all got the response in 5 seconds, no extra time.
The issue really comes from your multiple tabs in same browser, don't worry.

2011/7/27 Branko Vukelić <bg.b...@gmail.com>
--
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 nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en



--

si ce message est crypté:
- PGP KeyID -> 0x2F080247
- ou http://naholyr.free.fr/naholyr.pubring.gpg

Brett Ritter

unread,
Jul 27, 2011, 7:10:51 AM7/27/11
to nod...@googlegroups.com
On Tue, Jul 26, 2011 at 6:50 PM, beatgammit <beatg...@gmail.com> wrote:
> These clients are all running on my machine in the same browser, but
> it appears to be making separate connections for each tab.

I was reading through the HTTP 1.1 spec
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html) for another
issue, and saw this:

"A single-user client SHOULD NOT maintain more than 2 connections with
any server or proxy."

Which likely explains your issue.
--
Brett Ritter / SwiftOne
swif...@swiftone.org

Mikeal Rogers

unread,
Jul 28, 2011, 7:04:20 PM7/28/11
to nod...@googlegroups.com
Nobody follows this, the browser's default connections per host is higher than 2.

-Mikeal

Dominic Tarr

unread,
Jul 29, 2011, 2:41:25 AM7/29/11
to nod...@googlegroups.com
also note that .request (in http) is limited to 5 open sockets by default.

Reply all
Reply to author
Forward
0 new messages