Write request + headers + payload body in single socket.write #233

Closed
mheffner opened this Issue May 28, 2013 · 0 comments

Projects

None yet

1 participant

@mheffner
Contributor

In POST requests, for example, the current code performs two writes:

  1. socket.write (request + request headers)
  2. socket.write(body)

In the case that the request + request headers + body could fit within a single packet, it would be preferable to buffer these requests and put them on the network using a single socket.write call. The current write-write-read pattern can have a negative impact if it triggers a certain aspect of Nagle's algorithm: http://en.wikipedia.org/wiki/Nagle's_algorithm

The various chunking and encoding options that exist for writing the body payload might make this difficult to do in any case but the general body==String case.

@geemus geemus added a commit that closed this issue May 30, 2013
@geemus geemus defer writing request + headers
allows whole request in single write for string bodies
closes #233
42d78dc
@geemus geemus closed this in 42d78dc May 30, 2013
@nelhage nelhage added a commit to nelhage/excon that referenced this issue Mar 4, 2016
@nelhage nelhage Write the first body chunk in the initial packet.
When #266 was fixed, it caused a regression in the behavior from #233,
which deliberately merged the initial writes to the socket, for network
efficiency and to avoid triggering the pathological behavior caused by
the combination of Nagle's Algorithm and TCP delayed ACKs.

Restore that optimization, in a slightly more general way: Do a
nonblocking read of an initial chunk of data off the provided body, and
merge that with the headers before sending.
8fc63ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment