waste less time on sending progress messages over the privsep pipe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
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) {