Commit 5672d305fae0ef2b4e6c9582d45af790a06fa134

Stefan Sperling 2020-03-18T16:13:46

waste less time on sending progress messages over the privsep pipe

diff --git a/libexec/got-fetch-pack/got-fetch-pack.c b/libexec/got-fetch-pack/got-fetch-pack.c
index d86b89f..6a3bed9 100644
--- a/libexec/got-fetch-pack/got-fetch-pack.c
+++ b/libexec/got-fetch-pack/got-fetch-pack.c
@@ -421,7 +421,6 @@ fetch_progress(struct imsgbuf *ibuf, const char *buf, size_t len)
 {
 	int i;
 
-
 	if (len == 0)
 		return NULL;
 
@@ -470,7 +469,7 @@ fetch_pack(int fd, int packfd, struct got_object_id *packid,
 	struct got_object_id *have, *want;
 	int is_firstpkt = 1, nref = 0, refsz = 16;
 	int i, n, req;
-	off_t packsz;
+	off_t packsz = 0, last_reported_packsz = 0;
 	char *id_str = NULL, *refname = NULL;
 	char *server_capabilities = NULL, *my_capabilities = NULL;
 	struct got_pathlist_head symrefs;
@@ -621,7 +620,6 @@ fetch_pack(int fd, int packfd, struct got_object_id *packid,
 	    strstr(my_capabilities, GOT_CAPA_SIDE_BAND_64K) != NULL)
 		have_sidebands = 1;
 
-	packsz = 0;
 	while (1) {
 		ssize_t r = 0, w;
 		int datalen = -1;
@@ -709,10 +707,19 @@ fetch_pack(int fd, int packfd, struct got_object_id *packid,
 			goto done;
 		}
 		packsz += w;
-		err = got_privsep_send_fetch_download_progress(ibuf, packsz);
-		if (err)
-			goto done;
+
+		/* Don't send too many progress privsep messages. */
+		if (packsz > last_reported_packsz + 1024) {
+			err = got_privsep_send_fetch_download_progress(ibuf,
+			    packsz);
+			if (err)
+				goto done;
+			last_reported_packsz = packsz;
+		}
 	}
+	err = got_privsep_send_fetch_download_progress(ibuf, packsz);
+	if (err)
+		goto done;
 done:
 	TAILQ_FOREACH(pe, &symrefs, entry) {
 		free((void *)pe->path);
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index b4e4dc2..1ac94bd 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -562,6 +562,8 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
 	ssize_t r, w;
 	int pass, have_ref_deltas = 0, first_delta_idx = -1;
 	size_t mapoff = 0;
+	int p_indexed = 0, last_p_indexed = -1;
+	int p_resolved = 0, last_p_resolved = -1;
 
 	/* Check pack file header. */
 	if (pack->map) {
@@ -649,10 +651,15 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
 	 */
 	pass = 1;
 	for (i = 0; i < nobj; i++) {
-		err = got_privsep_send_index_pack_progress(ibuf, nobj, i + 1,
-		    nloose, 0);
-		if (err)
-			goto done;
+		/* Don't send too many progress privsep messages. */
+		p_indexed = ((i + 1) * 100) / nobj;
+		if (p_indexed != last_p_indexed) {
+			err = got_privsep_send_index_pack_progress(ibuf,
+			    nobj, i + 1, nloose, 0);
+			if (err)
+				goto done;
+			last_p_indexed = p_indexed;
+		}
 
 		obj = &objects[i];
 		obj->crc = crc32(0L, NULL, 0);
@@ -750,10 +757,15 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
 			n++;
 			if (have_ref_deltas)
 				update_packidx(&packidx, nobj, obj);
-			err = got_privsep_send_index_pack_progress(ibuf,
-			    nobj, nobj, nloose, nresolved + n);
-			if (err)
-				goto done;
+			/* Don't send too many progress privsep messages. */
+			p_resolved = ((nresolved + n) * 100) / nobj;
+			if (p_resolved != last_p_resolved) {
+				err = got_privsep_send_index_pack_progress(ibuf,
+				    nobj, nobj, nloose, nresolved + n);
+				if (err)
+					goto done;
+				last_p_resolved = p_resolved;
+			}
 
 		}
 		if (pass++ > 3 && n == 0) {