aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 04:09:42 +0000
committertv <tv@krebsco.de>2026-12-01 04:09:42 +0000
commita658ecba09821b0306e287c1c6691dd4804d74db (patch)
tree550db2c9f5fdd270fb9bf083311f2443c9b002a0 /pkgs/populate
parent3aff9c58c68d6882294e6586ddb384709ce95abe (diff)
populate: probe in parallel
The probe took most of a no-op run: 430 of the bench's 640 ms locally, walking the target paths of 100 sources one after another, a work tree of a git source in about 20 ms. It probes them in parallel now, in waves of as many as the target has processors, each into a file of its own in a private temporary directory, printed in order, so what it prints stays the same. A probe that dies on the way prints no exit status for its path, which leaves the path unprobed, so that source gets delivered. The probe takes 195 ms, the bench's no-op run 430 ms.
Diffstat (limited to 'pkgs/populate')
-rw-r--r--pkgs/populate/docs/design.md3
-rw-r--r--pkgs/populate/src/sh.rs33
2 files changed, 31 insertions, 5 deletions
diff --git a/pkgs/populate/docs/design.md b/pkgs/populate/docs/design.md
index f98a2f9..8268498 100644
--- a/pkgs/populate/docs/design.md
+++ b/pkgs/populate/docs/design.md
@@ -113,7 +113,8 @@ and about 45 ms of rsync waiting for its own processes, also when there's
nothing to transfer. So sources with nothing to do get skipped: right
after taking the lock, one command on the target, the probe (`probe.rs`),
finds out what's at the target paths of those whose lock file the flakes
-step doesn't rewrite:
+step doesn't rewrite, in parallel, as many at a time as the target has
+processors:
- For file sources that are directories, compared by size and time, a
listing, with find. Each such source's turn lists what rsync would
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 9d2b1d4..0c200ce 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -353,8 +353,10 @@ fi
/// and HEAD, U and the origin's URL, D and what git status prints for
/// anything modified, untracked, or ignored, and, with submodules, M and
/// what git submodule status prints for them, and S and an exit status,
-/// all separated by NULs. Git runs like the git script runs it, without
-/// hooks and file system monitors, and without writing the index.
+/// all separated by NULs. The pairs get probed in parallel, as many at a
+/// time as there are processors, and printed in order. Git runs like the
+/// git script runs it, without hooks and file system monitors, and without
+/// writing the index.
pub fn probe() -> String {
GIT_PROBLEMS.to_string()
+ r#"
@@ -362,9 +364,9 @@ git() {
command git -c core.hooksPath=/dev/null -c core.fsmonitor=false \
--no-optional-locks "$@"
}
-while test $# -gt 1; do
+# probe_one KIND PATH: what the probe prints for one pair.
+probe_one() {
kind=$1 path=$2
- shift 2
printf 'P\0%s\0' "$path"
status=0
case $kind in
@@ -408,6 +410,29 @@ while test $# -gt 1; do
;;
esac
printf 'S\0%s\0' "$status"
+}
+# In waves of as many as there are processors, each into a file of its
+# own in a private directory, printed in order afterwards. A probe that
+# dies on the way prints no S, which leaves its path unprobed.
+probes=$(mktemp -d)
+trap 'rm -fR "$probes"' EXIT
+jobs=$(nproc 2>/dev/null) || jobs=4
+n=0 running=0
+while test $# -gt 1; do
+ n=$((n + 1))
+ probe_one "$1" "$2" > "$probes/$n" &
+ shift 2
+ running=$((running + 1))
+ if test "$running" -ge "$jobs"; then
+ wait
+ running=0
+ fi
+done
+wait
+i=1
+while test "$i" -le "$n"; do
+ cat "$probes/$i"
+ i=$((i + 1))
done
"#
}
[cgit] Unable to lock slot /tmp/cgit/c6200000.lock: Permission denied (13)