New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

mheffner opened this Issue May 28, 2013 · 0 comments


None yet
1 participant

mheffner commented May 28, 2013

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:'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 closed this in 42d78dc May 30, 2013

nelhage added a commit to nelhage/excon that referenced this issue Mar 4, 2016

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment