From c12f5917e4f528b056a8b9ca625397aee97ae1e4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 20 Mar 2011 21:52:40 -0700 Subject: [PATCH 1/3] fetch-pack: factor out hardcoded handshake window size The "git fetch" client presents the most recent 32 commits it has to the server and gives a chance to the server to say "ok, we heard enough", and continues reporting what it has in chunks of 32 commits, digging its history down to older commits. Move the hardcoded size of the handshake window outside the code, so that we can tweak it more easily. Signed-off-by: Junio C Hamano Acked-by: Shawn Pearce --- builtin/fetch-pack.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 59fbda522b..1abe624dc8 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -218,11 +218,18 @@ static void send_request(int fd, struct strbuf *buf) safe_write(fd, buf->buf, buf->len); } +#define INITIAL_FLUSH 32 + +static int next_flush(int count) +{ + return INITIAL_FLUSH + count; +} + static int find_common(int fd[2], unsigned char *result_sha1, struct ref *refs) { int fetching; - int count = 0, flushes = 0, retval; + int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval; const unsigned char *sha1; unsigned in_vain = 0; int got_continue = 0; @@ -335,19 +342,20 @@ static int find_common(int fd[2], unsigned char *result_sha1, if (args.verbose) fprintf(stderr, "have %s\n", sha1_to_hex(sha1)); in_vain++; - if (!(31 & ++count)) { + if (flush_at <= ++count) { int ack; packet_buf_flush(&req_buf); send_request(fd[1], &req_buf); strbuf_setlen(&req_buf, state_len); flushes++; + flush_at = next_flush(count); /* * We keep one window "ahead" of the other side, and * will wait for an ACK only on the next one */ - if (!args.stateless_rpc && count == 32) + if (!args.stateless_rpc && count == INITIAL_FLUSH) continue; consume_shallow_list(fd[0]); From 6afca450c3f2f05385900a7b8d3a0d47286f983f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 20 Mar 2011 21:52:44 -0700 Subject: [PATCH 2/3] fetch-pack: progressively use larger handshake windows The client has to dig the history deeper when more recent parts of its history do not have any overlap with the server it is fetching from. Make the handshake window exponentially larger as we dig deeper, with a reasonable upper cap. Signed-off-by: Junio C Hamano Acked-by: Shawn Pearce --- builtin/fetch-pack.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 1abe624dc8..b4f34a2cf9 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -219,10 +219,15 @@ static void send_request(int fd, struct strbuf *buf) } #define INITIAL_FLUSH 32 +#define LARGE_FLUSH 1024 static int next_flush(int count) { - return INITIAL_FLUSH + count; + if (count < LARGE_FLUSH) + count <<= 1; + else + count += LARGE_FLUSH; + return count; } static int find_common(int fd[2], unsigned char *result_sha1, From 066bf4c2e43c7fb40405843e49f809431314865d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 20 Mar 2011 21:52:45 -0700 Subject: [PATCH 3/3] fetch-pack: use smaller handshake window for initial request Start the initial request small by halving the INITIAL_FLUSH (we will try to stay one window ahead of the server, so we would end up giving twice as many "have" in flight at the very beginning). We may want to tweak these values even more, taking MTU into account. Signed-off-by: Junio C Hamano Acked-by: Shawn Pearce --- builtin/fetch-pack.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index b4f34a2cf9..3c2c9406c4 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -218,12 +218,14 @@ static void send_request(int fd, struct strbuf *buf) safe_write(fd, buf->buf, buf->len); } -#define INITIAL_FLUSH 32 +#define INITIAL_FLUSH 16 #define LARGE_FLUSH 1024 static int next_flush(int count) { - if (count < LARGE_FLUSH) + if (count < INITIAL_FLUSH * 2) + count += INITIAL_FLUSH; + else if (count < LARGE_FLUSH) count <<= 1; else count += LARGE_FLUSH;