HTTP Server Concurrent Requests

1,244 views
Skip to first unread message

Russell

unread,
Aug 25, 2010, 11:38:47 PM8/25/10
to nod...@googlegroups.com
So I just noticed that the HTTP server in node v0.2.0 doesn't seem to be able to handle multiple concurrent requests. Demo code is at http://gist.github.com/550726

Am I doing something wrong here?

Guillermo Rauch

unread,
Aug 26, 2010, 12:08:43 AM8/26/10
to nod...@googlegroups.com
It looks like you're reusing a single Client instance as opposed to creating multiple

Sent from my iPhone

On Aug 25, 2010, at 8:38 PM, Russell <russell...@gmail.com> wrote:

So I just noticed that the HTTP server in node v0.2.0 doesn't seem to be able to handle multiple concurrent requests. Demo code is at http://gist.github.com/550726

Am I doing something wrong here?

--
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.

r...@tinyclouds.org

unread,
Aug 26, 2010, 12:06:28 AM8/26/10
to nod...@googlegroups.com

http.Client is a single TCP stream, not a pool of HTTP connections.
HTTP does not support concurrent requests, only pipelining - which
Node's client avoids because it's not well supported by servers.
(Node's HTTP server does support clients who send pipelined requests.)

Timothy Caswell

unread,
Aug 26, 2010, 12:14:11 AM8/26/10
to nod...@googlegroups.com
Correct, I'm doing the same thing, or at least used to, but now it seems a single client instance can only do one request as a time.

Was it ever able to do more before, or are we both just imagining things?

Matt Ranney

unread,
Aug 26, 2010, 12:14:52 AM8/26/10
to nod...@googlegroups.com
On Wed, Aug 25, 2010 at 8:38 PM, Russell <russell...@gmail.com> wrote:
So I just noticed that the HTTP server in node v0.2.0 doesn't seem to be able to handle multiple concurrent requests. Demo code is at http://gist.github.com/550726

The server should handle multiple concurrent requests.  I pretty regularly test with over 60,000.

In this case, your client code is only using a single connection.  If you want each request to run in its own connection, you'll need to make 10 clients as well as 10 requests.

Russell

unread,
Aug 26, 2010, 12:16:42 AM8/26/10
to nod...@googlegroups.com
Ah, you're right. I'd assumed the client could pipeline requests. False alarm.

Thanks,
-Russell

Isaac Schlueter

unread,
Aug 26, 2010, 12:17:05 AM8/26/10
to nod...@googlegroups.com
Everyone already answered in words. Here it is in code:

var http = require('http')

http.createServer(function (request, response) {
console.log(request.url+" Request received")
setTimeout(function() {
console.log(request.url+" Response sent")
response.writeHead(200, {'Content-Type': 'text/plain'})
response.end('Hello World\n')
}, 1000)
}).listen(8124)

for (var i = 0; i < 10; i++) {
var client = http.createClient(8124);
var request = client.request('GET', '/'+i, {'host': 'localhost'})
request.end()
console.log("/"+i+" Request sent")
}

--i

Isaac Schlueter

unread,
Aug 26, 2010, 12:23:43 AM8/26/10
to nod...@googlegroups.com
On Wed, Aug 25, 2010 at 21:14, Timothy Caswell <t...@creationix.com> wrote:
> Correct, I'm doing the same thing, or at least used to, but now it seems a
> single client instance can only do one request as a time.
> Was it ever able to do more before, or are we both just imagining things?

Pretty sure you're imagining things. At least as long as I've been
messing with it, this is how node's http client has worked.

A single *server* can handle lots of requests at once. But a single
*client* can only process one request at a time. Additional requests
stack up and wait their turn.

--i

Marak Squires

unread,
Aug 26, 2010, 12:34:00 AM8/26/10
to nod...@googlegroups.com
setting a one second timeout isn't going to help much either.

Timothy Caswell

unread,
Aug 26, 2010, 12:35:07 AM8/26/10
to nod...@googlegroups.com
Sounds good to me. I've used the server a lot more than client, so I very well may have been confused.

Though for my couchdb driver, is it possible to do pipelining (in the client) or is that support not there?

I'm fine with a connection pool if it's not there.

Adam

unread,
Dec 6, 2013, 11:23:38 AM12/6/13
to nod...@googlegroups.com
Three years has gone by since this last email and I wondered if anything changed since? Can a node.js client pipeline http requests (on a single keep-alive socket) rather than make each one wait until the last one completes?

Thanks in advance
Adam

Mikeal Rogers

unread,
Dec 6, 2013, 11:30:05 AM12/6/13
to nod...@googlegroups.com
Back then we spent a good amount of time debating whether or not this mattered. I remember that Ryan was particularly enamored with pipelining.

What it really comes down to is that pipelineing is almost never faster than a keep-alive pool. The reason is that the client has no idea how long each response will take and if the 2nd response takes 10x longer than the other 10 it'll end up making all of the responses that much slower. It turns out that pipelining just kinda sucks because of the requirement that responses be returned in order.

This is all fixed with SPDY. SPDY allows you to return responses out of order, which is fantastic.

-Mikeal


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
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Adam Griffiths

unread,
Dec 6, 2013, 3:49:35 PM12/6/13
to nod...@googlegroups.com, nod...@googlegroups.com
Great advice, thanks Mikeal

Adam


You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/z0xMSW5riDI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages