Skip to contentSkip to conversation

fetch-pack: add tracing for negotiation rounds

PATCH Superseded Josh Steadmon 3 participants 7 messages Jul 25, 2022 – Aug 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch-pack: add tracing for negotiation rounds

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Fix this by adding per-round trace2 regions for all negotiation implementations (V0+V1, V2, and independent negotiation), as well as an overall region for independent negotiation. Add trace2 data logging for the number of haves and "in vain" objects for each round, and for the total number of rounds once negotiation completes. Finally, add a few checks into various tests to verify that the number of rounds is logged as expected.

---
 fetch-pack.c                       | 62 +++++++++++++++++++++++++++++-
 t/t5500-fetch-pack.sh              |  4 +-
 t/t5516-fetch-push.sh              | 10 ++++-
 t/t5601-clone.sh                   |  6 ++-
 t/t5703-upload-pack-ref-in-want.sh |  6 ++-
 5 files changed, 81 insertions(+), 7 deletions(-)
fetch-pack.c +61 -1
index cb6647d657..01a451e456 100644
@@ -299,6 +299,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 {
 	int fetching;
 	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+	int negotiation_round = 0, haves = 0;
 	const struct object_id *oid;
 	unsigned in_vain = 0;
 	int got_continue = 0;
@@ -441,9 +442,19 @@ static int find_common(struct fetch_negotiator *negotiator,
 		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
 		print_verbose(args, "have %s", oid_to_hex(oid));
 		in_vain++;
+		haves++;
 		if (flush_at <= ++count) {
 			int ack;
 
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "haves_added", haves);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "in_vain", in_vain);
+			haves = 0;
 			packet_buf_flush(&req_buf);
 			send_request(args, fd[1], &req_buf);
 			strbuf_setlen(&req_buf, state_len);
@@ -465,6 +476,9 @@ static int find_common(struct fetch_negotiator *negotiator,
 						      ack, oid_to_hex(result_oid));
 				switch (ack) {
 				case ACK:
+					trace2_region_leave_printf("negotiation_v0_v1", "round",
+								   the_repository, "round-%d",
+								   negotiation_round);
 					flushes = 0;
 					multi_ack = 0;
 					retval = 0;
@@ -490,6 +504,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 						const char *hex = oid_to_hex(result_oid);
 						packet_buf_write(&req_buf, "have %s\n", hex);
 						state_len = req_buf.len;
+						haves++;
 						/*
 						 * Reset in_vain because an ack
 						 * for this commit has not been
@@ -510,14 +525,26 @@ static int find_common(struct fetch_negotiator *negotiator,
 			flushes--;
 			if (got_continue && MAX_IN_VAIN < in_vain) {
 				print_verbose(args, _("giving up"));
+				trace2_region_leave_printf("negotiation_v0_v1", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 				break; /* give up */
 			}
-			if (got_ready)
+			if (got_ready) {
+				trace2_region_leave_printf("negotiation_v0_v1", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 				break;
+			}
+			trace2_region_leave_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 		}
 	}
 done:
 	trace2_region_leave("fetch-pack", "negotiation_v0_v1", the_repository);
+	trace2_data_intmax("negotiation_v0_v1", the_repository, "total_rounds",
+			   negotiation_round);
 	if (!got_ready || !no_done) {
 		packet_buf_write(&req_buf, "done\n");
 		send_request(args, fd[1], &req_buf);
@@ -1361,6 +1388,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
 
 	haves_added = add_haves(negotiator, &req_buf, haves_to_send);
 	*in_vain += haves_added;
+	trace2_data_intmax("negotiation_v2", the_repository, "haves_added", haves_added);
+	trace2_data_intmax("negotiation_v2", the_repository, "in_vain", *in_vain);
 	if (!haves_added || (seen_ack && *in_vain >= MAX_IN_VAIN)) {
 		/* Send Done */
 		packet_buf_write(&req_buf, "done\n");
@@ -1603,6 +1632,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 	struct oidset common = OIDSET_INIT;
 	struct packet_reader reader;
 	int in_vain = 0, negotiation_started = 0;
+	int negotiation_round = 0;
 	int haves_to_send = INITIAL_FLUSH;
 	struct fetch_negotiator negotiator_alloc;
 	struct fetch_negotiator *negotiator;
@@ -1659,6 +1689,10 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 						    "negotiation_v2",
 						    the_repository);
 			}
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v2", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 			if (send_fetch_request(negotiator, fd[1], args, ref,
 					       &common,
 					       &haves_to_send, &in_vain,
@@ -1686,12 +1720,20 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 			} else {
 				do_check_stateless_delimiter(args->stateless_rpc, &reader);
 				state = FETCH_SEND_REQUEST;
+				trace2_region_leave_printf("negotiation_v2", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 			}
 			break;
 		case FETCH_GET_PACK:
+			trace2_region_leave_printf("negotiation_v2", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 			trace2_region_leave("fetch-pack",
 					    "negotiation_v2",
 					    the_repository);
+			trace2_data_intmax("negotiation_v2", the_repository,
+					   "total_rounds", negotiation_round);
 			/* Check for shallow-info section */
 			if (process_section_header(&reader, "shallow-info", 1))
 				receive_shallow_info(args, &reader, shallows, si);
@@ -2071,6 +2113,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 	int in_vain = 0;
 	int seen_ack = 0;
 	int last_iteration = 0;
+	int negotiation_round = 0;
 	timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
 
 	fetch_negotiator_init(the_repository, &negotiator);
@@ -2084,11 +2127,17 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 			   add_to_object_array,
 			   &nt_object_array);
 
+	trace2_region_enter("fetch-pack", "negotiate_using_fetch", the_repository);
 	while (!last_iteration) {
 		int haves_added;
 		struct object_id common_oid;
 		int received_ready = 0;
 
+		negotiation_round++;
+
+		trace2_region_enter_printf("negotiate_using_fetch", "round",
+					   the_repository, "round-%d",
+					   negotiation_round);
 		strbuf_reset(&req_buf);
 		write_fetch_command_and_capabilities(&req_buf, server_options);
 
@@ -2099,6 +2148,11 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 		if (!haves_added || (seen_ack && in_vain >= MAX_IN_VAIN))
 			last_iteration = 1;
 
+		trace2_data_intmax("negotiate_using_fetch", the_repository,
+				   "haves_added", haves_added);
+		trace2_data_intmax("negotiate_using_fetch", the_repository,
+				   "in_vain", in_vain);
+
 		/* Send request */
 		packet_buf_flush(&req_buf);
 		if (write_in_full(fd[1], req_buf.buf, req_buf.len) < 0)
@@ -2131,7 +2185,13 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 						 REACH_SCRATCH, 0,
 						 min_generation))
 			last_iteration = 1;
+		trace2_region_leave_printf("negotiation", "round",
+					   the_repository, "round-%d",
+					   negotiation_round);
 	}
+	trace2_region_enter("fetch-pack", "negotiate_using_fetch", the_repository);
+	trace2_data_intmax("negotiate_using_fetch", the_repository,
+			   "total_rounds", negotiation_round);
 	clear_common_flag(acked_commits);
 	strbuf_release(&req_buf);
 }
t/t5500-fetch-pack.sh +3 -1
index ee6d2dde9f..d18f2823d8 100755
@@ -407,6 +407,7 @@ test_expect_success 'in_vain not triggered before first ACK' '
 '
 
 test_expect_success 'in_vain resetted upon ACK' '
+	test_when_finished rm -f log trace2 &&
 	rm -rf myserver myclient &&
 	git init myserver &&
 
@@ -432,7 +433,8 @@ test_expect_success 'in_vain resetted upon ACK' '
 	# first. The 256th commit is common between the client and the server,
 	# and should reset in_vain. This allows negotiation to continue until
 	# the client reports that first_anotherbranch_commit is common.
-	git -C myclient fetch --progress origin main 2>log &&
+	GIT_TRACE2_EVENT="$(pwd)/trace2" git -C myclient fetch --progress origin main 2>log &&
+	grep \"key\":\"total_rounds\",\"value\":\"6\" trace2 &&
 	test_i18ngrep "Total 3 " log
 '
 
t/t5516-fetch-push.sh +8 -2
index 9ca0f8c144..f64cefa29a 100755
@@ -198,7 +198,10 @@ test_expect_success 'push with negotiation' '
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
 	test_when_finished "rm event" &&
-	GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
+	GIT_TRACE2_EVENT="$(pwd)/event" \
+		git -c protocol.version=2 -c push.negotiate=1 \
+		push testrepo refs/heads/main:refs/remotes/origin/main &&
+	grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
 	grep_wrote 2 event # 1 commit, 1 tree
 '
 
@@ -222,7 +225,10 @@ test_expect_success 'push with negotiation does not attempt to fetch submodules'
 	git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
-	git -c submodule.recurse=true -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
+	GIT_TRACE2_EVENT="$(pwd)/event"  git -c submodule.recurse=true \
+		-c protocol.version=2 -c push.negotiate=1 \
+		push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
+	grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
 	! grep "Fetching submodule" err
 '
 
t/t5601-clone.sh +5 -1
index cf3be0584f..2e57de9c12 100755
@@ -743,7 +743,11 @@ test_expect_success 'batch missing blob request during checkout' '
 
 	# Ensure that there is only one negotiation by checking that there is
 	# only "done" line sent. ("done" marks the end of negotiation.)
-	GIT_TRACE_PACKET="$(pwd)/trace" git -C client checkout HEAD^ &&
+	GIT_TRACE_PACKET="$(pwd)/trace" \
+		GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
+		git -C client -c trace2.eventNesting=5 checkout HEAD^ &&
+	grep \"key\":\"total_rounds\",\"value\":\"1\" trace2_event >trace_lines &&
+	test_line_count = 1 trace_lines &&
 	grep "fetch> done" trace >done_lines &&
 	test_line_count = 1 done_lines
 '
t/t5703-upload-pack-ref-in-want.sh +4 -2
index 9d6cd7d986..df74f80061 100755
@@ -229,14 +229,16 @@ test_expect_success 'setup repos for fetching with ref-in-want tests' '
 '
 
 test_expect_success 'fetching with exact OID' '
-	test_when_finished "rm -f log" &&
+	test_when_finished "rm -f log trace2" &&
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
 	oid=$(git -C "$REPO" rev-parse d) &&
-	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
+	GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE2_EVENT="$(pwd)/trace2" \
+		git -C local fetch origin \
 		"$oid":refs/heads/actual &&
 
+	grep \"key\":\"total_rounds\",\"value\":\"2\" trace2 &&
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&

base-commit: 4e2a4d1dd44367d7783f33b169698f2930ff13c0

Signature · 1 line
2.37.1.359.gd136c6c3e2-goog
#1 lore raw
Quoted 7 lines · Josh Steadmon

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Quite sensibly argued. I do not necessarily see the current code as "broken", and "fix" at the beginning of the next line may not be an appropriate word to describe this enhancement, but I think it would be nice to have such numbers.

Quoted 14 lines
fetch-pack.c +1 -0
index cb6647d657..01a451e456 100644
@@ -299,6 +299,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 {
 	int fetching;
 	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+	int negotiation_round = 0, haves = 0;
 	const struct object_id *oid;
 	unsigned in_vain = 0;
 	int got_continue = 0;
@@ -441,9 +442,19 @@ static int find_common(struct fetch_negotiator *negotiator,
 		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 452

Quoted 10 lines
fetch-pack.c +5 -0
 		print_verbose(args, "have %s", oid_to_hex(oid));
 		in_vain++;
+		haves++;
 		if (flush_at <= ++count) {
 			int ack;
 
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);

Not an objection, but all the hits to existing calls to this function show the data in a format as vanilla as possible without frills (presumably to make it easier to mechanically parse the value out when needed???), and the "round-" prefix we see here somehow looks out of place. Doesn't the fact that the record is in the "negotiation_v0_v1" category and has label "round" clear enough sign that the value presented is the negotiation_round?

Quoted 36 lines
fetch-pack.c +12 -1
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "haves_added", haves);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "in_vain", in_vain);
+			haves = 0;
 			packet_buf_flush(&req_buf);
 			send_request(args, fd[1], &req_buf);
 			strbuf_setlen(&req_buf, state_len);
@@ -465,6 +476,9 @@ static int find_common(struct fetch_negotiator *negotiator,
 						      ack, oid_to_hex(result_oid));
 				switch (ack) {
 				case ACK:
+					trace2_region_leave_printf("negotiation_v0_v1", "round",
+								   the_repository, "round-%d",
+								   negotiation_round);
 					flushes = 0;
 					multi_ack = 0;
 					retval = 0;
@@ -490,6 +504,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 						const char *hex = oid_to_hex(result_oid);
 						packet_buf_write(&req_buf, "have %s\n", hex);
 						state_len = req_buf.len;
+						haves++;
 						/*
 						 * Reset in_vain because an ack
 						 * for this commit has not been
@@ -510,14 +525,26 @@ static int find_common(struct fetch_negotiator *negotiator,
 			flushes--;
 			if (got_continue && MAX_IN_VAIN < in_vain) {
 				print_verbose(args, _("giving up"));
+				trace2_region_leave_printf("negotiation_v0_v1", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 				break; /* give up */
 			}
-			if (got_ready)

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 542

Quoted 10 lines
fetch-pack.c +8 -0
+			if (got_ready) {
+				trace2_region_leave_printf("negotiation_v0_v1", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 				break;
+			}
+			trace2_region_leave_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 		}

Having many duplicated calls to "leave" makes the whole thing look somewhat confused. Is this primarily because we have too many "break" that breaks out of the loop?

Quoted 22 lines
fetch-pack.c +5 -0
@@ -1603,6 +1632,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 	struct oidset common = OIDSET_INIT;
 	struct packet_reader reader;
 	int in_vain = 0, negotiation_started = 0;
+	int negotiation_round = 0;
 	int haves_to_send = INITIAL_FLUSH;
 	struct fetch_negotiator negotiator_alloc;
 	struct fetch_negotiator *negotiator;
@@ -1659,6 +1689,10 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 						    "negotiation_v2",
 						    the_repository);
 			}
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v2", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 			if (send_fetch_request(negotiator, fd[1], args, ref,
 					       &common,
 					       &haves_to_send, &in_vain,
@@ -1686,12 +1720,20 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 			} else {
 				do_check_stateless_delimiter(args->stateless_rpc, &reader);

fetch-pack.c static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, · line 1731

Quoted 10 lines
fetch-pack.c +6 -0
 				state = FETCH_SEND_REQUEST;
+				trace2_region_leave_printf("negotiation_v2", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 			}
 			break;
 		case FETCH_GET_PACK:
+			trace2_region_leave_printf("negotiation_v2", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);

Hmph. Doesn't this logically belong to the "FETCH_PROCESS_ACKS" case arm? We "leave" the current round when we did not get "ready" and "enter" the next round by moving to "FETCH_SEND_REQUEST" state, but at the same location when we did get "ready", we can "leave" the current (and final) round and move to "FETCH_GET_PACK" state. I suspect the code structure and control flow becomes easier to see when expressed that way.

Quoted 8 lines
fetch-pack.c +2 -0
 			trace2_region_leave("fetch-pack",
 					    "negotiation_v2",
 					    the_repository);
+			trace2_data_intmax("negotiation_v2", the_repository,
+					   "total_rounds", negotiation_round);
 			/* Check for shallow-info section */
 			if (process_section_header(&reader, "shallow-info", 1))
 				receive_shallow_info(args, &reader, shallows, si);
#3 lore raw
In reply to Josh Steadmon
Quoted 8 lines · Josh Steadmon

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Quoted 7 lines

Fix this by adding per-round trace2 regions for all negotiation implementations (V0+V1, V2, and independent negotiation), as well as an overall region for independent negotiation. Add trace2 data logging for the number of haves and "in vain" objects for each round, and for the total number of rounds once negotiation completes. Finally, add a few checks into various tests to verify that the number of rounds is logged as expected.

I've been wanting to add data like this around the negotiation code for a while now. Thanks!

Quoted 24 lines
---
  fetch-pack.c                       | 62 +++++++++++++++++++++++++++++-
  t/t5500-fetch-pack.sh              |  4 +-
  t/t5516-fetch-push.sh              | 10 ++++-
  t/t5601-clone.sh                   |  6 ++-
  t/t5703-upload-pack-ref-in-want.sh |  6 ++-
  5 files changed, 81 insertions(+), 7 deletions(-)
fetch-pack.c +1 -0
index cb6647d657..01a451e456 100644
@@ -299,6 +299,7 @@ static int find_common(struct fetch_negotiator *negotiator,
  {
  	int fetching;
  	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+	int negotiation_round = 0, haves = 0;
  	const struct object_id *oid;
  	unsigned in_vain = 0;
  	int got_continue = 0;
@@ -441,9 +442,19 @@ static int find_common(struct fetch_negotiator *negotiator,
  		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 452

Quoted 10 lines
fetch-pack.c +5 -0
  		print_verbose(args, "have %s", oid_to_hex(oid));
  		in_vain++;
+		haves++;
  		if (flush_at <= ++count) {
  			int ack;
 
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);

I'm wondering here if the "round-%d" should have some number of leading zeros so that multiple rounds will sort correctly when you have a bunch of them.

I'm also wondering (and this is more of a style thing, so feel free to ignore) if we could just use trace2_region_enter() and make the "label" field be the "round/%04d" and not need the extra args.

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 457

Quoted 5 lines
fetch-pack.c +5 -0
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "haves_added", haves);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "in_vain", in_vain);
+			haves = 0;

Thanks,
Jeff

#2 lore raw
In reply to Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Josh Steadmon

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Quoted 4 lines

Quite sensibly argued. I do not necessarily see the current code as "broken", and "fix" at the beginning of the next line may not be an appropriate word to describe this enhancement, but I think it would be nice to have such numbers.

Reworded that sentence.

Quoted 20 lines
Quoted 20 lines
fetch-pack.c +2 -0
index cb6647d657..01a451e456 100644
@@ -299,6 +299,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 {
 	int fetching;
 	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+	int negotiation_round = 0, haves = 0;
 	const struct object_id *oid;
 	unsigned in_vain = 0;
 	int got_continue = 0;
@@ -441,9 +442,19 @@ static int find_common(struct fetch_negotiator *negotiator,
 		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
 		print_verbose(args, "have %s", oid_to_hex(oid));
 		in_vain++;
+		haves++;
 		if (flush_at <= ++count) {
 			int ack;
 
Quoted 12 lines

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 452

Quoted 4 lines
fetch-pack.c +4 -0
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);

Not an objection, but all the hits to existing calls to this function show the data in a format as vanilla as possible without frills (presumably to make it easier to mechanically parse the value out when needed???), and the "round-" prefix we see here somehow looks out of place. Doesn't the fact that the record is in the "negotiation_v0_v1" category and has label "round" clear enough sign that the value presented is the negotiation_round?

True, fixed in V2.

Quoted 42 lines
Quoted 42 lines
fetch-pack.c +17 -1
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "haves_added", haves);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "in_vain", in_vain);
+			haves = 0;
 			packet_buf_flush(&req_buf);
 			send_request(args, fd[1], &req_buf);
 			strbuf_setlen(&req_buf, state_len);
@@ -465,6 +476,9 @@ static int find_common(struct fetch_negotiator *negotiator,
 						      ack, oid_to_hex(result_oid));
 				switch (ack) {
 				case ACK:
+					trace2_region_leave_printf("negotiation_v0_v1", "round",
+								   the_repository, "round-%d",
+								   negotiation_round);
 					flushes = 0;
 					multi_ack = 0;
 					retval = 0;
@@ -490,6 +504,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 						const char *hex = oid_to_hex(result_oid);
 						packet_buf_write(&req_buf, "have %s\n", hex);
 						state_len = req_buf.len;
+						haves++;
 						/*
 						 * Reset in_vain because an ack
 						 * for this commit has not been
@@ -510,14 +525,26 @@ static int find_common(struct fetch_negotiator *negotiator,
 			flushes--;
 			if (got_continue && MAX_IN_VAIN < in_vain) {
 				print_verbose(args, _("giving up"));
+				trace2_region_leave_printf("negotiation_v0_v1", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 				break; /* give up */
 			}
-			if (got_ready)
+			if (got_ready) {
+				trace2_region_leave_printf("negotiation_v0_v1", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 				break;
+			}
Quoted 8 lines

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 532

Quoted 4 lines
fetch-pack.c +3 -0
+			trace2_region_leave_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 		}

Having many duplicated calls to "leave" makes the whole thing look somewhat confused. Is this primarily because we have too many "break" that breaks out of the loop?

Yes, although now that I look at it again, I believe as soon as we finish the do-while, we know that the round is over, so I believe we can just put a single region_leave there. Fixed in V2.

Quoted 33 lines
Quoted 22 lines
fetch-pack.c +5 -0
@@ -1603,6 +1632,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 	struct oidset common = OIDSET_INIT;
 	struct packet_reader reader;
 	int in_vain = 0, negotiation_started = 0;
+	int negotiation_round = 0;
 	int haves_to_send = INITIAL_FLUSH;
 	struct fetch_negotiator negotiator_alloc;
 	struct fetch_negotiator *negotiator;
@@ -1659,6 +1689,10 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 						    "negotiation_v2",
 						    the_repository);
 			}
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v2", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
 			if (send_fetch_request(negotiator, fd[1], args, ref,
 					       &common,
 					       &haves_to_send, &in_vain,
@@ -1686,12 +1720,20 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 			} else {
 				do_check_stateless_delimiter(args->stateless_rpc, &reader);

fetch-pack.c static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, · line 1731

Quoted 10 lines
fetch-pack.c +6 -0
 				state = FETCH_SEND_REQUEST;
+				trace2_region_leave_printf("negotiation_v2", "round",
+							   the_repository, "round-%d",
+							   negotiation_round);
 			}
 			break;
 		case FETCH_GET_PACK:
+			trace2_region_leave_printf("negotiation_v2", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);
Quoted 7 lines

Hmph. Doesn't this logically belong to the "FETCH_PROCESS_ACKS" case arm? We "leave" the current round when we did not get "ready" and "enter" the next round by moving to "FETCH_SEND_REQUEST" state, but at the same location when we did get "ready", we can "leave" the current (and final) round and move to "FETCH_GET_PACK" state. I suspect the code structure and control flow becomes easier to see when expressed that way.

That works, but then we also need an additional region_leave in the FETCH_SEND_REQUEST case where we jump directly to FETCH_GET_PACK. I'm not sure which way is more intuitive, but I've gone with your suggestion for V2.

Quoted 8 lines
Quoted 8 lines
fetch-pack.c +2 -0
 			trace2_region_leave("fetch-pack",
 					    "negotiation_v2",
 					    the_repository);
+			trace2_data_intmax("negotiation_v2", the_repository,
+					   "total_rounds", negotiation_round);
 			/* Check for shallow-info section */
 			if (process_section_header(&reader, "shallow-info", 1))
 				receive_shallow_info(args, &reader, shallows, si);
#4 lore raw
In reply to Jeff Hostetler
Quoted 60 lines · Jeff Hostetler
Quoted 8 lines · Josh Steadmon

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Quoted 7 lines

Fix this by adding per-round trace2 regions for all negotiation implementations (V0+V1, V2, and independent negotiation), as well as an overall region for independent negotiation. Add trace2 data logging for the number of haves and "in vain" objects for each round, and for the total number of rounds once negotiation completes. Finally, add a few checks into various tests to verify that the number of rounds is logged as expected.

I've been wanting to add data like this around the negotiation code for a while now. Thanks!

Quoted 23 lines
---
  fetch-pack.c                       | 62 +++++++++++++++++++++++++++++-
  t/t5500-fetch-pack.sh              |  4 +-
  t/t5516-fetch-push.sh              | 10 ++++-
  t/t5601-clone.sh                   |  6 ++-
  t/t5703-upload-pack-ref-in-want.sh |  6 ++-
  5 files changed, 81 insertions(+), 7 deletions(-)
fetch-pack.c +1 -0
index cb6647d657..01a451e456 100644
@@ -299,6 +299,7 @@ static int find_common(struct fetch_negotiator *negotiator,
  {
  	int fetching;
  	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+	int negotiation_round = 0, haves = 0;
  	const struct object_id *oid;
  	unsigned in_vain = 0;
  	int got_continue = 0;

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 451

Quoted 10 lines
fetch-pack.c +5 -0
@@ -441,9 +442,19 @@ static int find_common(struct fetch_negotiator *negotiator,
  		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
  		print_verbose(args, "have %s", oid_to_hex(oid));
  		in_vain++;
+		haves++;
  		if (flush_at <= ++count) {
  			int ack;
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v0_v1", "round",
+						   the_repository, "round-%d",
+						   negotiation_round);

I'm wondering here if the "round-%d" should have some number of leading zeros so that multiple rounds will sort correctly when you have a bunch of them.

Quoted 4 lines

I'm also wondering (and this is more of a style thing, so feel free to ignore) if we could just use trace2_region_enter() and make the "label" field be the "round/%04d" and not need the extra args.

Junio suggested just dropping the prefix altogether, so that's what I've done for V2, but if you feel strongly about it we can discuss further for V3.

Quoted 8 lines

fetch-pack.c static int find_common(struct fetch_negotiator *negotiator, · line 457

Quoted 5 lines
fetch-pack.c +5 -0
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "haves_added", haves);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "in_vain", in_vain);
+			haves = 0;

Thanks,
Jeff

#5 lore raw

PATCH v2 1/1 fetch-pack: add tracing for negotiation rounds

In reply to Josh Steadmon

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Add per-round trace2 regions for all negotiation implementations (V0+V1, V2, and independent negotiation), as well as an overall region for independent negotiation. Add trace2 data logging for the number of haves and "in vain" objects for each round, and for the total number of rounds once negotiation completes. Finally, add a few checks into various tests to verify that the number of rounds is logged as expected.

---
Changes since V1:
* Removed "round-" prefix in per-round region messages.
* Deduplicate some trace2_region_leave_printf() calls.
* Clarified the commit message.

Range-diff against v1:
1: a16d86e1ce ! 1: 4390677ec7 fetch-pack: add tracing for negotiation rounds

    @@ Commit message
         performance of the various negotation implementations, and to debug
         unexpectedly slow fetch & push sessions.
     
    -    Fix this by adding per-round trace2 regions for all negotiation
    -    implementations (V0+V1, V2, and independent negotiation), as well as an
    -    overall region for independent negotiation. Add trace2 data logging for
    -    the number of haves and "in vain" objects for each round, and for the
    -    total number of rounds once negotiation completes.  Finally, add a few
    -    checks into various tests to verify that the number of rounds is logged
    -    as expected.
    +    Add per-round trace2 regions for all negotiation implementations (V0+V1,
    +    V2, and independent negotiation), as well as an overall region for
    +    independent negotiation. Add trace2 data logging for the number of haves
    +    and "in vain" objects for each round, and for the total number of rounds
    +    once negotiation completes.  Finally, add a few checks into various
    +    tests to verify that the number of rounds is logged as expected.
     
     
    @@ fetch-pack.c: static int find_common(struct fetch_negotiator *negotiator,
      
     +			negotiation_round++;
     +			trace2_region_enter_printf("negotiation_v0_v1", "round",
    -+						   the_repository, "round-%d",
    ++						   the_repository, "%d",
     +						   negotiation_round);
     +			trace2_data_intmax("negotiation_v0_v1", the_repository,
     +					   "haves_added", haves);
    @@ fetch-pack.c: static int find_common(struct fetch_negotiator *negotiator,
      				switch (ack) {
      				case ACK:
     +					trace2_region_leave_printf("negotiation_v0_v1", "round",
    -+								   the_repository, "round-%d",
    ++								   the_repository, "%d",
     +								   negotiation_round);
      					flushes = 0;
      					multi_ack = 0;
    @@ fetch-pack.c: static int find_common(struct fetch_negotiator *negotiator,
      						 * Reset in_vain because an ack
      						 * for this commit has not been
     @@ fetch-pack.c: static int find_common(struct fetch_negotiator *negotiator,
    + 				}
    + 			} while (ack);
      			flushes--;
    ++			trace2_region_leave_printf("negotiation_v0_v1", "round",
    ++						   the_repository, "%d",
    ++						   negotiation_round);
      			if (got_continue && MAX_IN_VAIN < in_vain) {
      				print_verbose(args, _("giving up"));
    -+				trace2_region_leave_printf("negotiation_v0_v1", "round",
    -+							   the_repository, "round-%d",
    -+							   negotiation_round);
      				break; /* give up */
    - 			}
    --			if (got_ready)
    -+			if (got_ready) {
    -+				trace2_region_leave_printf("negotiation_v0_v1", "round",
    -+							   the_repository, "round-%d",
    -+							   negotiation_round);
    - 				break;
    -+			}
    -+			trace2_region_leave_printf("negotiation_v0_v1", "round",
    -+						   the_repository, "round-%d",
    -+						   negotiation_round);
    - 		}
    +@@ fetch-pack.c: static int find_common(struct fetch_negotiator *negotiator,
      	}
      done:
      	trace2_region_leave("fetch-pack", "negotiation_v0_v1", the_repository);
    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      			}
     +			negotiation_round++;
     +			trace2_region_enter_printf("negotiation_v2", "round",
    -+						   the_repository, "round-%d",
    ++						   the_repository, "%d",
     +						   negotiation_round);
      			if (send_fetch_request(negotiator, fd[1], args, ref,
      					       &common,
      					       &haves_to_send, &in_vain,
    -@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
    - 			} else {
    - 				do_check_stateless_delimiter(args->stateless_rpc, &reader);
    - 				state = FETCH_SEND_REQUEST;
    + 					       reader.use_sideband,
    +-					       seen_ack))
    ++					       seen_ack)) {
     +				trace2_region_leave_printf("negotiation_v2", "round",
    -+							   the_repository, "round-%d",
    ++							   the_repository, "%d",
     +							   negotiation_round);
    - 			}
    + 				state = FETCH_GET_PACK;
    ++			}
    + 			else
    + 				state = FETCH_PROCESS_ACKS;
      			break;
    - 		case FETCH_GET_PACK:
    +@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
    + 				seen_ack = 1;
    + 				oidset_insert(&common, &common_oid);
    + 			}
     +			trace2_region_leave_printf("negotiation_v2", "round",
    -+						   the_repository, "round-%d",
    ++						   the_repository, "%d",
     +						   negotiation_round);
    + 			if (received_ready) {
    + 				/*
    + 				 * Don't check for response delimiter; get_pack() will
    +@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      			trace2_region_leave("fetch-pack",
      					    "negotiation_v2",
      					    the_repository);
    @@ fetch-pack.c: void negotiate_using_fetch(const struct oid_array *negotiation_tip
     +		negotiation_round++;
     +
     +		trace2_region_enter_printf("negotiate_using_fetch", "round",
    -+					   the_repository, "round-%d",
    ++					   the_repository, "%d",
     +					   negotiation_round);
      		strbuf_reset(&req_buf);
      		write_fetch_command_and_capabilities(&req_buf, server_options);
    @@ fetch-pack.c: void negotiate_using_fetch(const struct oid_array *negotiation_tip
      						 min_generation))
      			last_iteration = 1;
     +		trace2_region_leave_printf("negotiation", "round",
    -+					   the_repository, "round-%d",
    ++					   the_repository, "%d",
     +					   negotiation_round);
      	}
     +	trace2_region_enter("fetch-pack", "negotiate_using_fetch", the_repository);
 fetch-pack.c                       | 56 +++++++++++++++++++++++++++++-
 t/t5500-fetch-pack.sh              |  4 ++-
 t/t5516-fetch-push.sh              | 10 ++++--
 t/t5601-clone.sh                   |  6 +++-
 t/t5703-upload-pack-ref-in-want.sh |  6 ++--
 5 files changed, 75 insertions(+), 7 deletions(-)
fetch-pack.c +55 -1
index cb6647d657..666aaa9a89 100644
@@ -299,6 +299,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 {
 	int fetching;
 	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
+	int negotiation_round = 0, haves = 0;
 	const struct object_id *oid;
 	unsigned in_vain = 0;
 	int got_continue = 0;
@@ -441,9 +442,19 @@ static int find_common(struct fetch_negotiator *negotiator,
 		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
 		print_verbose(args, "have %s", oid_to_hex(oid));
 		in_vain++;
+		haves++;
 		if (flush_at <= ++count) {
 			int ack;
 
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v0_v1", "round",
+						   the_repository, "%d",
+						   negotiation_round);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "haves_added", haves);
+			trace2_data_intmax("negotiation_v0_v1", the_repository,
+					   "in_vain", in_vain);
+			haves = 0;
 			packet_buf_flush(&req_buf);
 			send_request(args, fd[1], &req_buf);
 			strbuf_setlen(&req_buf, state_len);
@@ -465,6 +476,9 @@ static int find_common(struct fetch_negotiator *negotiator,
 						      ack, oid_to_hex(result_oid));
 				switch (ack) {
 				case ACK:
+					trace2_region_leave_printf("negotiation_v0_v1", "round",
+								   the_repository, "%d",
+								   negotiation_round);
 					flushes = 0;
 					multi_ack = 0;
 					retval = 0;
@@ -490,6 +504,7 @@ static int find_common(struct fetch_negotiator *negotiator,
 						const char *hex = oid_to_hex(result_oid);
 						packet_buf_write(&req_buf, "have %s\n", hex);
 						state_len = req_buf.len;
+						haves++;
 						/*
 						 * Reset in_vain because an ack
 						 * for this commit has not been
@@ -508,6 +523,9 @@ static int find_common(struct fetch_negotiator *negotiator,
 				}
 			} while (ack);
 			flushes--;
+			trace2_region_leave_printf("negotiation_v0_v1", "round",
+						   the_repository, "%d",
+						   negotiation_round);
 			if (got_continue && MAX_IN_VAIN < in_vain) {
 				print_verbose(args, _("giving up"));
 				break; /* give up */
@@ -518,6 +536,8 @@ static int find_common(struct fetch_negotiator *negotiator,
 	}
 done:
 	trace2_region_leave("fetch-pack", "negotiation_v0_v1", the_repository);
+	trace2_data_intmax("negotiation_v0_v1", the_repository, "total_rounds",
+			   negotiation_round);
 	if (!got_ready || !no_done) {
 		packet_buf_write(&req_buf, "done\n");
 		send_request(args, fd[1], &req_buf);
@@ -1361,6 +1381,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
 
 	haves_added = add_haves(negotiator, &req_buf, haves_to_send);
 	*in_vain += haves_added;
+	trace2_data_intmax("negotiation_v2", the_repository, "haves_added", haves_added);
+	trace2_data_intmax("negotiation_v2", the_repository, "in_vain", *in_vain);
 	if (!haves_added || (seen_ack && *in_vain >= MAX_IN_VAIN)) {
 		/* Send Done */
 		packet_buf_write(&req_buf, "done\n");
@@ -1603,6 +1625,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 	struct oidset common = OIDSET_INIT;
 	struct packet_reader reader;
 	int in_vain = 0, negotiation_started = 0;
+	int negotiation_round = 0;
 	int haves_to_send = INITIAL_FLUSH;
 	struct fetch_negotiator negotiator_alloc;
 	struct fetch_negotiator *negotiator;
@@ -1659,12 +1682,20 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 						    "negotiation_v2",
 						    the_repository);
 			}
+			negotiation_round++;
+			trace2_region_enter_printf("negotiation_v2", "round",
+						   the_repository, "%d",
+						   negotiation_round);
 			if (send_fetch_request(negotiator, fd[1], args, ref,
 					       &common,
 					       &haves_to_send, &in_vain,
 					       reader.use_sideband,
-					       seen_ack))
+					       seen_ack)) {
+				trace2_region_leave_printf("negotiation_v2", "round",
+							   the_repository, "%d",
+							   negotiation_round);
 				state = FETCH_GET_PACK;
+			}
 			else
 				state = FETCH_PROCESS_ACKS;
 			break;
@@ -1677,6 +1708,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 				seen_ack = 1;
 				oidset_insert(&common, &common_oid);
 			}
+			trace2_region_leave_printf("negotiation_v2", "round",
+						   the_repository, "%d",
+						   negotiation_round);
 			if (received_ready) {
 				/*
 				 * Don't check for response delimiter; get_pack() will
@@ -1692,6 +1726,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 			trace2_region_leave("fetch-pack",
 					    "negotiation_v2",
 					    the_repository);
+			trace2_data_intmax("negotiation_v2", the_repository,
+					   "total_rounds", negotiation_round);
 			/* Check for shallow-info section */
 			if (process_section_header(&reader, "shallow-info", 1))
 				receive_shallow_info(args, &reader, shallows, si);
@@ -2071,6 +2107,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 	int in_vain = 0;
 	int seen_ack = 0;
 	int last_iteration = 0;
+	int negotiation_round = 0;
 	timestamp_t min_generation = GENERATION_NUMBER_INFINITY;
 
 	fetch_negotiator_init(the_repository, &negotiator);
@@ -2084,11 +2121,17 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 			   add_to_object_array,
 			   &nt_object_array);
 
+	trace2_region_enter("fetch-pack", "negotiate_using_fetch", the_repository);
 	while (!last_iteration) {
 		int haves_added;
 		struct object_id common_oid;
 		int received_ready = 0;
 
+		negotiation_round++;
+
+		trace2_region_enter_printf("negotiate_using_fetch", "round",
+					   the_repository, "%d",
+					   negotiation_round);
 		strbuf_reset(&req_buf);
 		write_fetch_command_and_capabilities(&req_buf, server_options);
 
@@ -2099,6 +2142,11 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 		if (!haves_added || (seen_ack && in_vain >= MAX_IN_VAIN))
 			last_iteration = 1;
 
+		trace2_data_intmax("negotiate_using_fetch", the_repository,
+				   "haves_added", haves_added);
+		trace2_data_intmax("negotiate_using_fetch", the_repository,
+				   "in_vain", in_vain);
+
 		/* Send request */
 		packet_buf_flush(&req_buf);
 		if (write_in_full(fd[1], req_buf.buf, req_buf.len) < 0)
@@ -2131,7 +2179,13 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips,
 						 REACH_SCRATCH, 0,
 						 min_generation))
 			last_iteration = 1;
+		trace2_region_leave_printf("negotiation", "round",
+					   the_repository, "%d",
+					   negotiation_round);
 	}
+	trace2_region_enter("fetch-pack", "negotiate_using_fetch", the_repository);
+	trace2_data_intmax("negotiate_using_fetch", the_repository,
+			   "total_rounds", negotiation_round);
 	clear_common_flag(acked_commits);
 	strbuf_release(&req_buf);
 }
t/t5500-fetch-pack.sh +3 -1
index ee6d2dde9f..d18f2823d8 100755
@@ -407,6 +407,7 @@ test_expect_success 'in_vain not triggered before first ACK' '
 '
 
 test_expect_success 'in_vain resetted upon ACK' '
+	test_when_finished rm -f log trace2 &&
 	rm -rf myserver myclient &&
 	git init myserver &&
 
@@ -432,7 +433,8 @@ test_expect_success 'in_vain resetted upon ACK' '
 	# first. The 256th commit is common between the client and the server,
 	# and should reset in_vain. This allows negotiation to continue until
 	# the client reports that first_anotherbranch_commit is common.
-	git -C myclient fetch --progress origin main 2>log &&
+	GIT_TRACE2_EVENT="$(pwd)/trace2" git -C myclient fetch --progress origin main 2>log &&
+	grep \"key\":\"total_rounds\",\"value\":\"6\" trace2 &&
 	test_i18ngrep "Total 3 " log
 '
 
t/t5516-fetch-push.sh +8 -2
index 9ca0f8c144..f64cefa29a 100755
@@ -198,7 +198,10 @@ test_expect_success 'push with negotiation' '
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
 	test_when_finished "rm event" &&
-	GIT_TRACE2_EVENT="$(pwd)/event" git -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main &&
+	GIT_TRACE2_EVENT="$(pwd)/event" \
+		git -c protocol.version=2 -c push.negotiate=1 \
+		push testrepo refs/heads/main:refs/remotes/origin/main &&
+	grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
 	grep_wrote 2 event # 1 commit, 1 tree
 '
 
@@ -222,7 +225,10 @@ test_expect_success 'push with negotiation does not attempt to fetch submodules'
 	git push testrepo $the_first_commit:refs/remotes/origin/first_commit &&
 	test_commit -C testrepo unrelated_commit &&
 	git -C testrepo config receive.hideRefs refs/remotes/origin/first_commit &&
-	git -c submodule.recurse=true -c protocol.version=2 -c push.negotiate=1 push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
+	GIT_TRACE2_EVENT="$(pwd)/event"  git -c submodule.recurse=true \
+		-c protocol.version=2 -c push.negotiate=1 \
+		push testrepo refs/heads/main:refs/remotes/origin/main 2>err &&
+	grep \"key\":\"total_rounds\",\"value\":\"1\" event &&
 	! grep "Fetching submodule" err
 '
 
t/t5601-clone.sh +5 -1
index cf3be0584f..2e57de9c12 100755
@@ -743,7 +743,11 @@ test_expect_success 'batch missing blob request during checkout' '
 
 	# Ensure that there is only one negotiation by checking that there is
 	# only "done" line sent. ("done" marks the end of negotiation.)
-	GIT_TRACE_PACKET="$(pwd)/trace" git -C client checkout HEAD^ &&
+	GIT_TRACE_PACKET="$(pwd)/trace" \
+		GIT_TRACE2_EVENT="$(pwd)/trace2_event" \
+		git -C client -c trace2.eventNesting=5 checkout HEAD^ &&
+	grep \"key\":\"total_rounds\",\"value\":\"1\" trace2_event >trace_lines &&
+	test_line_count = 1 trace_lines &&
 	grep "fetch> done" trace >done_lines &&
 	test_line_count = 1 done_lines
 '
t/t5703-upload-pack-ref-in-want.sh +4 -2
index 9d6cd7d986..df74f80061 100755
@@ -229,14 +229,16 @@ test_expect_success 'setup repos for fetching with ref-in-want tests' '
 '
 
 test_expect_success 'fetching with exact OID' '
-	test_when_finished "rm -f log" &&
+	test_when_finished "rm -f log trace2" &&
 
 	rm -rf local &&
 	cp -r "$LOCAL_PRISTINE" local &&
 	oid=$(git -C "$REPO" rev-parse d) &&
-	GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
+	GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE2_EVENT="$(pwd)/trace2" \
+		git -C local fetch origin \
 		"$oid":refs/heads/actual &&
 
+	grep \"key\":\"total_rounds\",\"value\":\"2\" trace2 &&
 	git -C "$REPO" rev-parse "d" >expected &&
 	git -C local rev-parse refs/heads/actual >actual &&
 	test_cmp expected actual &&

base-commit: 4e2a4d1dd44367d7783f33b169698f2930ff13c0

Signature · 1 line
2.37.1.455.g008518b4e5-goog
#6 lore raw
Quoted 8 lines · Josh Steadmon

Currently, negotiation for V0/V1/V2 fetch have trace2 regions covering the entire negotiation process. However, we'd like additional data, such as timing for each round of negotiation or the number of "haves" in each round. Additionally, "independent negotiation" (AKA push negotiation) has no tracing at all. Having this data would allow us to compare the performance of the various negotation implementations, and to debug unexpectedly slow fetch & push sessions.

Quoted 8 lines

Add per-round trace2 regions for all negotiation implementations (V0+V1, V2, and independent negotiation), as well as an overall region for independent negotiation. Add trace2 data logging for the number of haves and "in vain" objects for each round, and for the total number of rounds once negotiation completes. Finally, add a few checks into various tests to verify that the number of rounds is logged as expected.

Sorry for the delay in responding. Just got back from a much needed vacation.

This version LGTM.

Thanks
Jeff