Does chunked encoding mean separate packets?

44 views
Skip to first unread message

Alice

unread,
Oct 15, 2011, 6:00:13 AM10/15/11
to nodejs
Does node send two network packets for this code? (One for "Hello,
World\n' and another for a zero length last chunk to indicate end of
the chunks)

res.write('Hello, World\n');
res.end();

The documentation says write does not buffer the output.

Ben Noordhuis

unread,
Oct 15, 2011, 11:58:07 AM10/15/11
to nod...@googlegroups.com
On Sat, Oct 15, 2011 at 12:00, Alice <doff...@gmail.com> wrote:
> Does node send two network packets for this code? (One for "Hello,
> World\n' and another for a zero length last chunk to indicate end of
> the chunks)
>
> res.write('Hello, World\n');
> res.end();

It may. Don't depend on that behaviour, Node is free to coalesce
multiple writes into a single one.

> The documentation says write does not buffer the output.

I don't see that mentioned anywhere[1].

[1] http://nodejs.org/docs/v0.5.9/api/http.html#response.write

Alice

unread,
Oct 15, 2011, 1:28:15 PM10/15/11
to nodejs
"The interface is careful to never buffer entire requests or
responses--the user is able to stream data."

I thought this means calling write immediately sends the packet. Are
you saying that Node uses timer and write can be buffered?

On Oct 16, 12:58 am, Ben Noordhuis <i...@bnoordhuis.nl> wrote:

Ben Noordhuis

unread,
Oct 15, 2011, 1:38:58 PM10/15/11
to nod...@googlegroups.com
On Sat, Oct 15, 2011 at 19:28, Alice <doff...@gmail.com> wrote:
> "The interface is careful to never buffer entire requests or
> responses--the user is able to stream data."
>
> I thought this means calling write immediately sends the packet. Are
> you saying that Node uses timer and write can be buffered?

Yes, but timer is the wrong word. The socket may not be ready to send
data when you call .write() so Node queues the data until it is.

Matt

unread,
Oct 15, 2011, 3:17:50 PM10/15/11
to nod...@googlegroups.com
Is there a way to use TCP_CORK from Node?

Ben Noordhuis

unread,
Oct 15, 2011, 5:08:18 PM10/15/11
to nod...@googlegroups.com

No. You probably don't need it for HTTP, Node does its own corking.
Though I wouldn't mind to be proven wrong with benchmark numbers. :-)

Matt

unread,
Oct 15, 2011, 5:46:16 PM10/15/11
to nod...@googlegroups.com
I recall that perlbal (perl load balancing epoll based http proxy) uses it to good effect. Nagle is designed for interactive apps, and isn't good for HTTP.

It might be nice for Haraka's outbound stuff too because I'm sending each line individually (and I assume that although node "buffers" it doesn't deal with this at the packet level).

Matt.
Reply all
Reply to author
Forward
0 new messages