sapling/eden
Thomas Orozco e2d1a43146 keepalive: send message body with the headers
Summary:
On the LFS Server, we've noted that LFS batch requests from Mercurial have
about ~40ms latency, but that the same request sent through curl doesn't.
Those requests, when sent through curl, complete in < 1ms, so thats a lot of overhead.
After adding more logging in the LFS server (D18636703), it turned out that that is
because the body of the request shows up 40ms after the request itself.

After capturing the traffic on the backend (D18689109), it turned out that
Mercurial is sending the headers and the response body in 2 separate TCP
packets.

The reason for that is delayed TCP acks. What happens is that when we call
`h.endheaders()`, that calls `send(2)`, which in turns send the packet with the
headers. Later, when we call `h.send(data)`, we make another `send(2)` syscall,
but that doesn't go over the wire immediately: because of Nagle's algorithm, we
wait for an ACK for the first packet we send before sending a new one, and
because of delayed ACKs, the ACK takes 40ms for this ACK to show up (which is
over 40 times the roundtrip latency!).

This diff passes the data to `h.endheaders()`, which in Python's httplib will
concatenate the headers and the data into a single  `send(2)` syscall if the
data isn't a file-like object (which it isn't for batch requests), and
otherwise fall back to doing exactly what we're doing right now.

This will result in everything in a single packet if we're fetching a single
file (and AFAICT, without further delay if we're fetching enough files that the
request doesn't fit in a single packet).

An alternative approach would be to set `TCP_NODELAY` on our socket here, but
for now this seems less intrusive and just as effective, so I've opted for that
approach.

Reviewed By: farnz

Differential Revision: D18811419

fbshipit-source-id: 4cf5719e5eed90e5dd994e6c8861aceb69373d89
2019-12-04 12:10:22 -08:00
..
benchmarks Remove dead includes in eden 2019-10-11 16:45:01 -07:00
cli eden: remove legacy bind mount concept from redirections 2019-12-04 10:47:14 -08:00
docs Document how globs work 2019-03-07 14:20:57 -08:00
fs build cleanly with -Wextra-semi 2019-12-03 15:04:27 -08:00
integration eden: remove legacy bind mount concept from redirections 2019-12-04 10:47:14 -08:00
locale add a copyright header to glibc_en.po 2019-04-26 14:38:27 -07:00
py Call WSAStartup and fix the type information for the socket APIs 2019-10-18 12:39:09 -07:00
scm keepalive: send message body with the headers 2019-12-04 12:10:22 -08:00
scripts Tidy up license headers 2019-10-11 05:28:23 -07:00
test_support Update pyre version for eden 2019-10-16 16:56:29 -07:00
test-data enable treemanifest in snapshots 2019-08-28 18:46:03 -07:00
third-party add osxfuse kernel header 2019-03-19 10:26:24 -07:00
win flip EDEN_WIN_NOMONONOKE to EDEN_HAVE_MONONOKE 2019-08-27 17:04:19 -07:00
.gitignore eden: wire up mac contbuild 2019-02-05 21:52:30 -08:00
Eden.project.toml Eden.project.toml file for Nuclide 2018-04-26 11:05:23 -07:00