From 4f7a8d12b5f303978e1d8a80b8d18cbbfa57c0d1 Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Thu, 12 Nov 2026 03:36:39 -0800 Subject: [PATCH 1/4] Measure: the census image build on sai with a build cache (#117) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycszSbyw92Efu4ZeCYL6 --- .github/workflows/measure-image-cache.yml | 219 ++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 .github/workflows/measure-image-cache.yml diff --git a/.github/workflows/measure-image-cache.yml b/.github/workflows/measure-image-cache.yml new file mode 100644 index 00000000..55a5187a --- /dev/null +++ b/.github/workflows/measure-image-cache.yml @@ -0,0 +1,219 @@ +# Temporary (census #117): how long the census image takes to build on sai, +# the self-hosted runner, with a build cache that stays on its disk, against +# GitHub's runners, where every build is cold (10-13 minutes for amd64). +# +# Each `sequence` leg builds morca-dev/census's amd64 image from its +# Dockerfile.orca, at a fixed commit, four times on a builder of its own, +# created empty for the job and removed after it: +# +# cold the empty builder +# warm again, the same commit +# src a line added to a file in src/ (a census-only commit) +# pin orca-mojo's pin moved to another morca commit, pixi.lock relocked +# (#117's case: the `env` stage and everything after it) +# +# `stock` is Dockerfile.orca as it is; `cache-mounts` adds BuildKit cache +# mounts for pixi's package cache and Mojo's compile cache. `concurrent` +# then runs two stock builds at once, on two of sai's runners. +# +# On pushes to this branch only (not pull_request): a push is always this +# repository's own branch, never a fork's, and the PR's own CI doesn't run +# it again. No secrets, and the token can only read. Nothing is pushed. +name: Measure image cache + +on: + push: + branches: [image-cache-sai] + paths: [.github/workflows/measure-image-cache.yml] + +permissions: + contents: read + +env: + CENSUS_SHA: 713fbe08c877d442411608daac8167693afe26e0 + # orca-mojo's pin at that commit is 480d2b4 (orca 0.24.0); 736569c is a + # later morca commit (#354, a src/ change) with the same dista pin. + PIN_TO: 736569c61d362975763725f378cf925ca1c37a87 + +jobs: + sequence: + if: github.repository == 'morca-dev/morca' + name: sequence (${{ matrix.variant }}) + runs-on: [self-hosted, sai] + timeout-minutes: 150 + strategy: + fail-fast: false + # One after the other, so neither shares sai with the other. + max-parallel: 1 + matrix: + variant: [stock, cache-mounts] + steps: + - uses: actions/checkout@v4 + with: + repository: morca-dev/census + ref: ${{ env.CENSUS_SHA }} + path: census + - uses: prefix-dev/setup-pixi@v0.10.2 + with: + pixi-version: v0.78.0 + run-install: false + cache: false + manifest-path: census/pixi.toml + pixi-bin-path: ${{ runner.temp }}/pixi/bin/pixi + - name: Prepare the variant and the src and pin copies + env: + VARIANT: ${{ matrix.variant }} + run: | + set -eux + docker version --format 'client {{.Client.Version}} server {{.Server.Version}}' + docker buildx version + lscpu | grep -E 'Model name|^CPU\(s\)' + if [ "$VARIANT" = cache-mounts ]; then + # pixi's package cache (conda packages, git checkouts) for + # `pixi install`, and Mojo's compile cache for the build. + sed -i \ + -e 's|^RUN pixi install --locked$|RUN --mount=type=cache,id=census-pixi,target=/root/.cache pixi install --locked|' \ + -e 's|^RUN mkdir -p /out/bin /out/pipelines \\$|RUN --mount=type=cache,id=census-max,target=/src/project/.pixi/envs/default/share/max/cache mkdir -p /out/bin /out/pipelines \\|' \ + census/Dockerfile.orca + grep -n -- '--mount' census/Dockerfile.orca + [ "$(grep -c -- '--mount' census/Dockerfile.orca)" = 2 ] + fi + cp -a census census-src + echo '# measure-image-cache: a census-only change' >> census-src/src/activity.mojo + cp -a census census-pin + cd census-pin + sed -i "s|morca-dev/morca.git\", rev = \"[0-9a-f]*\"|morca-dev/morca.git\", rev = \"$PIN_TO\"|" pixi.toml + grep -n 'orca-mojo' pixi.toml + pixi lock + git diff --stat + - name: Builds + shell: bash + env: + VARIANT: ${{ matrix.variant }} + RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.variant }} + run: | + set -euo pipefail + B="measure-$RUN_KEY" + echo "B=$B" >> "$GITHUB_ENV" + docker buildx create --name "$B" --driver docker-container > /dev/null + docker buildx inspect --bootstrap "$B" | grep -E 'Driver|Status|Buildkit' || true + root=$(docker info -f '{{.DockerRootDir}}') + echo "docker root: $root" + summary() { echo "$*" >> "$GITHUB_STEP_SUMMARY"; } + summary "### $VARIANT on $RUNNER_NAME" + summary "" + summary "| build | seconds | pixi install | mojo build (apps / pipelines) | git | load before → after | builder cache |" + summary "|---|---|---|---|---|---|---|" + build() { # NAME DIR COMMIT + name=$1 dir=$2 commit=$3 + load0=$(cut -d' ' -f1-3 /proc/loadavg) + t=$(date +%s) + docker buildx build --builder "$B" --load --progress=plain \ + -f "$dir/Dockerfile.orca" -t "census-measure:$RUN_KEY-$name" \ + --build-arg ORCA_SOURCE=https://github.com/morca-dev/census \ + --build-arg ORCA_COMMIT="$commit" \ + --build-arg MOJO_TARGET_CPU=x86-64-v3 \ + "$dir" > "build-$name.log" 2>&1 || { tail -80 "build-$name.log"; exit 1; } + s=$(($(date +%s) - t)) + load1=$(cut -d' ' -f1-3 /proc/loadavg) + # The step numbers of `pixi install` and the git build, and how + # long each took (CACHED when it was). + step_time() { # PATTERN + n=$(grep -m1 -E "^#[0-9]+ \[.*$1" "build-$name.log" | sed -E 's/^#([0-9]+).*/\1/') + [ -n "$n" ] || { echo "-"; return; } + grep -m1 -E "^#$n (DONE [0-9.]+s|CACHED)" "build-$name.log" | sed -E "s/^#$n //" || echo "?" + } + pixi_t=$(step_time 'RUN .*pixi install') + git_t=$(step_time 'git 4/4') + mojo_t=$(grep -E 'build.sh: multicall-(apps|pipelines) in' "build-$name.log" | sed -E 's/.*multicall-([a-z]+) in ([0-9]+) s/\2/' | paste -sd/ -) + [ -n "$mojo_t" ] || mojo_t=CACHED + du=$(docker buildx du --builder "$B" 2>/dev/null | awk '/^Total:/ {print $2}') + echo "== $name: $s s (pixi install $pixi_t, mojo $mojo_t, git $git_t), load $load0 -> $load1, cache $du" + grep -E 'build.sh:|peak memory' "build-$name.log" || true + summary "| $name | $s | $pixi_t | $mojo_t | $git_t | $load0 → $load1 | $du |" + } + df -h "$HOME" | tail -1 + build cold census "$CENSUS_SHA" + build warm census "$CENSUS_SHA" + build src census-src "${CENSUS_SHA:0:20}00000000000000000001" + build pin census-pin "${CENSUS_SHA:0:20}00000000000000000002" + docker image ls "census-measure" --format '{{.Tag}} {{.Size}}' + docker buildx du --builder "$B" | tail -25 + df -h "$HOME" | tail -1 + - name: Remove the builder and the images + if: always() + shell: bash + run: | + [ -n "${B:-}" ] && docker buildx rm "$B" || true + docker image ls census-measure --format '{{.Repository}}:{{.Tag}}' | xargs -r docker image rm > /dev/null || true + df -h "$HOME" | tail -1 + - uses: actions/upload-artifact@v4 + if: always() + with: + name: build-logs-${{ matrix.variant }} + path: build-*.log + retention-days: 7 + + # Two cold builds at once, then two warm ones (the src change), on two of + # sai's runners: what a second build costs the first. + concurrent: + if: github.repository == 'morca-dev/morca' + needs: sequence + name: concurrent (${{ matrix.leg }}) + runs-on: [self-hosted, sai] + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + leg: [1, 2] + steps: + - uses: actions/checkout@v4 + with: + repository: morca-dev/census + ref: ${{ env.CENSUS_SHA }} + path: census + - name: Builds + shell: bash + env: + RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }}-conc-${{ matrix.leg }} + run: | + set -euo pipefail + cp -a census census-src + echo '# measure-image-cache: a census-only change' >> census-src/src/activity.mojo + B="measure-$RUN_KEY" + echo "B=$B" >> "$GITHUB_ENV" + docker buildx create --name "$B" --driver docker-container > /dev/null + docker buildx inspect --bootstrap "$B" > /dev/null + summary() { echo "$*" >> "$GITHUB_STEP_SUMMARY"; } + summary "### concurrent leg ${{ matrix.leg }} on $RUNNER_NAME" + summary "" + summary "| build | started | seconds | mojo build (apps / pipelines) | load before → after |" + summary "|---|---|---|---|---|" + build() { # NAME DIR COMMIT + name=$1 dir=$2 commit=$3 + load0=$(cut -d' ' -f1-3 /proc/loadavg) + start=$(date -u +%H:%M:%S) + t=$(date +%s) + docker buildx build --builder "$B" --load --progress=plain \ + -f "$dir/Dockerfile.orca" -t "census-measure:$RUN_KEY-$name" \ + --build-arg ORCA_SOURCE=https://github.com/morca-dev/census \ + --build-arg ORCA_COMMIT="$commit" \ + --build-arg MOJO_TARGET_CPU=x86-64-v3 \ + "$dir" > "build-$name.log" 2>&1 || { tail -80 "build-$name.log"; exit 1; } + s=$(($(date +%s) - t)) + load1=$(cut -d' ' -f1-3 /proc/loadavg) + mojo_t=$(grep -E 'build.sh: multicall-(apps|pipelines) in' "build-$name.log" | sed -E 's/.*multicall-([a-z]+) in ([0-9]+) s/\2/' | paste -sd/ -) + echo "== $name: started $start, $s s, mojo $mojo_t, load $load0 -> $load1" + summary "| $name | $start | $s | $mojo_t | $load0 → $load1 |" + } + build cold census "$CENSUS_SHA" + build src census-src "${CENSUS_SHA:0:20}00000000000000000001" + docker buildx du --builder "$B" | tail -1 + df -h "$HOME" | tail -1 + - name: Remove the builder and the images + if: always() + shell: bash + run: | + [ -n "${B:-}" ] && docker buildx rm "$B" || true + docker image ls census-measure --format '{{.Repository}}:{{.Tag}}' | xargs -r docker image rm > /dev/null || true + df -h "$HOME" | tail -1 From 86e09e0976566e104f9c613089590944cafefe12 Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Thu, 12 Nov 2026 03:48:43 -0800 Subject: [PATCH 2/4] Measure: no pipefail, so a CACHED build's empty greps don't stop the job Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycszSbyw92Efu4ZeCYL6 --- .github/workflows/measure-image-cache.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/measure-image-cache.yml b/.github/workflows/measure-image-cache.yml index 55a5187a..60fb6b7e 100644 --- a/.github/workflows/measure-image-cache.yml +++ b/.github/workflows/measure-image-cache.yml @@ -92,7 +92,7 @@ jobs: VARIANT: ${{ matrix.variant }} RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.variant }} run: | - set -euo pipefail + set -eu B="measure-$RUN_KEY" echo "B=$B" >> "$GITHUB_ENV" docker buildx create --name "$B" --driver docker-container > /dev/null @@ -177,7 +177,7 @@ jobs: env: RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }}-conc-${{ matrix.leg }} run: | - set -euo pipefail + set -eu cp -a census census-src echo '# measure-image-cache: a census-only change' >> census-src/src/activity.mojo B="measure-$RUN_KEY" From eb1f0c149448a989c2a92bd63e54372251ba204e Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Thu, 12 Nov 2026 04:00:50 -0800 Subject: [PATCH 3/4] Measure: turn off the pipefail that shell: bash adds Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycszSbyw92Efu4ZeCYL6 --- .github/workflows/measure-image-cache.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/measure-image-cache.yml b/.github/workflows/measure-image-cache.yml index 60fb6b7e..72f62681 100644 --- a/.github/workflows/measure-image-cache.yml +++ b/.github/workflows/measure-image-cache.yml @@ -92,7 +92,7 @@ jobs: VARIANT: ${{ matrix.variant }} RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.variant }} run: | - set -eu + set -eu +o pipefail # shell: bash runs with -o pipefail B="measure-$RUN_KEY" echo "B=$B" >> "$GITHUB_ENV" docker buildx create --name "$B" --driver docker-container > /dev/null @@ -177,7 +177,7 @@ jobs: env: RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }}-conc-${{ matrix.leg }} run: | - set -eu + set -eu +o pipefail # shell: bash runs with -o pipefail cp -a census census-src echo '# measure-image-cache: a census-only change' >> census-src/src/activity.mojo B="measure-$RUN_KEY" From 0f3e4b05acdbb17cb25ce679bfc1e79c04198d9e Mon Sep 17 00:00:00 2001 From: Marius S <39998+winding-lines@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:30:40 -0800 Subject: [PATCH 4/4] Measure: multicall-pipelines against its programs built alone, on sai (census #153) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017TycszSbyw92Efu4ZeCYL6 --- .github/measure/split-build.sh | 206 ++++++++++++++++++++++ .github/workflows/measure-split-build.yml | 92 ++++++++++ 2 files changed, 298 insertions(+) create mode 100755 .github/measure/split-build.sh create mode 100644 .github/workflows/measure-split-build.yml diff --git a/.github/measure/split-build.sh b/.github/measure/split-build.sh new file mode 100755 index 00000000..7dd3c2ea --- /dev/null +++ b/.github/measure/split-build.sh @@ -0,0 +1,206 @@ +#!/bin/bash +# Temporary (census #153): run inside the census's `env` stage, under +# `pixi run`, by .github/workflows/measure-split-build.yml. Builds the +# programs of multicall-pipelines four ways, each with an empty Mojo compile +# cache of its own, and writes the results to $RESULTS: +# +# combined multicall-pipelines, as scripts/multicall.sh builds it +# seq each program alone, one after the other +# par4 each program alone, 4 at a time (xargs -P 4) +# par8 each program alone, 8 at a time +# +# The flags are scripts/build.sh's in the image: -g1 --target-cpu x86-64-v3 +# and the two -D MORCA_* values. +set -eu +RESULTS=${RESULTS:-/results} +CENSUS_SHA=${CENSUS_SHA:-unknown} +mkdir -p "$RESULTS" +trap 'chown -R "${HOST_UID:-0}:${HOST_GID:-0}" "$RESULTS" 2> /dev/null || true' EXIT +cd /src/project +flags=(-g1 --target-cpu x86-64-v3 -D MORCA_SOURCE=https://github.com/morca-dev/census -D "MORCA_COMMIT=$CENSUS_SHA") +inc=(-I bin -I pipelines -I src) + +# The programs of multicall-pipelines, as scripts/build.sh lists them. +apps="bin/scheduler.mojo" +[ -f bin/console.mojo ] && apps="$apps bin/console.mojo" +progs="" +for f in bin/*.mojo pipelines/*.mojo; do + [ -f "$f" ] || continue + case " $apps " in *" $f "*) continue ;; esac + progs="$progs $f" +done +echo "programs:$progs" +echo "nproc $(nproc), $(grep -m1 'model name' /proc/cpuinfo), mem $(awk '/^MemTotal/ {printf "%d", $2 / 1048576}' /proc/meminfo) GB" +mojo --version + +# The compile cache modular.cfg names, emptied before each measurement, and +# MODULAR_CACHE_DIR, a new empty directory for each mojo build. +cfg_cache=$(sed -n 's/^cache_dir *= *//p' "$CONDA_PREFIX/share/max/modular.cfg" | head -1) +echo "modular.cfg cache_dir: ${cfg_cache:-none}" +cold() { + if [ -n "$cfg_cache" ]; then rm -rf "$cfg_cache"; fi + rm -rf /caches + mkdir -p /caches +} + +# Peak anonymous memory of the container's cgroup (what the builds hold, +# not the page cache), sampled every 0.5 s while a measurement runs. +sampler_start() { # FILE + ( peak=0 + while :; do + a=$(awk '/^anon / {print $2}' /sys/fs/cgroup/memory.stat 2> /dev/null || echo 0) + [ "$a" -gt "$peak" ] && { peak=$a; echo "$peak" > "$1"; } + sleep 0.5 + done ) & + sampler=$! +} +sampler_stop() { kill "$sampler" 2> /dev/null || true; wait "$sampler" 2> /dev/null || true; } + +# GNU time's -v fields. +tv() { sed -n "s/^[[:space:]]*$2: //p" "$1" | head -1; } + +# One program alone: OUT_DIR PROGRAM.mojo, timed into OUT_DIR/NAME.time. +cat > /usr/local/bin/build-one << 'EOF' +#!/bin/bash +set -eu +out=$1 prog=$2 +name=$(basename "$prog" .mojo) +export MODULAR_CACHE_DIR=/caches/$name-$$ +mkdir -p "$MODULAR_CACHE_DIR" +s=$(date +%s.%N) +/usr/bin/time -v -o "$out/$name.time" mojo build $INC $FLAGS "$prog" -o "$out/$name" > "$out/$name.log" 2>&1 \ + || { echo "FAILED $name"; cat "$out/$name.log"; exit 1; } +echo "$(date +%s.%N) $s" | awk '{printf "%.1f\n", $1 - $2}' > "$out/$name.wall" +echo " $name $(cat "$out/$name.wall") s" +EOF +chmod +x /usr/local/bin/build-one +export INC="${inc[*]}" FLAGS="${flags[*]}" + +load() { cut -d' ' -f1-3 /proc/loadavg; } +# MEASUREMENT: wall, user, sys, max RSS of one process, peak anon, load. +record() { # NAME TIMEFILE WALL PEAKFILE LOAD0 + printf '%s\t%s\t%s\t%s\t%s\t%s\t%s → %s\n' "$1" "$3" "$(tv "$2" 'User time (seconds)')" \ + "$(tv "$2" 'System time (seconds)')" "$(tv "$2" 'Maximum resident set size (kbytes)')" \ + "$(cat "$4" 2> /dev/null || echo 0)" "$5" "$(load)" >> "$RESULTS/runs.tsv" +} +: > "$RESULTS/runs.tsv" +: > "$RESULTS/seq.tsv" + +# 1. combined +echo "== combined" +cold +l0=$(load) +sampler_start /tmp/peak-combined +s=$(date +%s) +MODULAR_CACHE_DIR=/caches/combined /usr/bin/time -v -o /tmp/combined.time \ + sh scripts/multicall.sh multicall-pipelines /m/combined/bin /m/combined/pipelines $progs -- "${flags[@]}" +w=$(($(date +%s) - s)) +sampler_stop +record combined /tmp/combined.time "$w" /tmp/peak-combined "$l0" +echo " $w s; cache $(du -sh /caches | cut -f1)" + +# 2. each alone, one after the other +echo "== seq" +cold +mkdir -p /m/seq +l0=$(load) +sampler_start /tmp/peak-seq +s=$(date +%s) +for p in $progs; do + build-one /m/seq "$p" +done +w=$(($(date +%s) - s)) +sampler_stop +for p in $progs; do + n=$(basename "$p" .mojo) + printf '%s\t%s\t%s\t%s\t%s\n' "$n" "$(cat /m/seq/$n.wall)" "$(tv /m/seq/$n.time 'User time (seconds)')" \ + "$(tv /m/seq/$n.time 'System time (seconds)')" "$(tv /m/seq/$n.time 'Maximum resident set size (kbytes)')" \ + >> "$RESULTS/seq.tsv" +done +# The sequence as one measurement: its user and sys are the programs' sums. +awk -F'\t' -v w="$w" '{u += $3; y += $4; if ($5 > m) m = $5} + END {printf "\tUser time (seconds): %.2f\n\tSystem time (seconds): %.2f\n\tMaximum resident set size (kbytes): %d\n", u, y, m}' \ + "$RESULTS/seq.tsv" > /tmp/seq.time +record seq /tmp/seq.time "$w" /tmp/peak-seq "$l0" +echo " $w s; cache $(du -sh /caches | cut -f1)" + +# 3. each alone, N at a time +for n in 4 8; do + echo "== par$n" + cold + mkdir -p /m/par$n + l0=$(load) + sampler_start /tmp/peak-par$n + s=$(date +%s) + printf '%s\n' $progs | /usr/bin/time -v -o /tmp/par$n.time xargs -P "$n" -n 1 build-one /m/par$n + w=$(($(date +%s) - s)) + sampler_stop + record par$n /tmp/par$n.time "$w" /tmp/peak-par$n "$l0" + echo " $w s; cache $(du -sh /caches | cut -f1)" +done +# xargs's own time sums its children's user and sys; max RSS is the +# largest one program's. + +# 4. sizes: raw, then with the Dockerfile's objcopy, then gzipped. +echo "== sizes" +size_of() { # FILES... -> raw objcopied gzipped (sums) + r=0 c=0 z=0 + for f in "$@"; do + r=$((r + $(stat -c %s "$f"))) + cp "$f" /tmp/sz && objcopy --compress-debug-sections=zlib /tmp/sz + c=$((c + $(stat -c %s /tmp/sz))) + z=$((z + $(gzip -c /tmp/sz | wc -c))) + done + echo "$r $c $z" +} +sep="" +for p in $progs; do sep="$sep /m/seq/$(basename "$p" .mojo)"; done +echo "combined $(size_of /m/combined/bin/multicall-pipelines)" > "$RESULTS/sizes.txt" +echo "separate $(size_of $sep)" >> "$RESULTS/sizes.txt" +for p in $progs; do + n=$(basename "$p" .mojo) + echo "$n $(size_of /m/seq/$n)" >> "$RESULTS/sizes-each.txt" +done +cat "$RESULTS/sizes.txt" +cat /sys/fs/cgroup/memory.peak > "$RESULTS/memory.peak" 2> /dev/null || true + +# The summary. +mb() { awk -v k="$1" 'BEGIN {printf "%.1f", k / 1048576}'; } +{ + echo "### Census #153: multicall-pipelines vs its programs built alone" + echo + echo "census $CENSUS_SHA, $(nproc) threads ($(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | sed 's/^ //')), $(mojo --version | head -1). Flags: \`${flags[*]}\`. Each measurement starts with an empty Mojo compile cache (MODULAR_CACHE_DIR new for each mojo build)." + echo + echo "| build | wall s | user+sys s | CPU / wall | largest process RSS GB | peak memory (cgroup anon) GB | load before → after |" + echo "|---|---|---|---|---|---|---|" + while IFS=$'\t' read -r name w u y rss peak ld; do + awk -v n="$name" -v w="$w" -v u="$u" -v y="$y" -v r="$rss" -v p="$peak" -v l="$ld" \ + 'BEGIN {printf "| %s | %d | %.0f | %.1f | %.1f | %.1f | %s |\n", n, w, u + y, (u + y) / w, r / 1048576, p / 1073741824, l}' + done < "$RESULTS/runs.tsv" + echo + echo "Each program alone (seq):" + echo + echo "| program | wall s | user+sys s | max RSS GB |" + echo "|---|---|---|---|" + awk -F'\t' '{printf "| %s | %.0f | %.0f | %.1f |\n", $1, $2, $3 + $4, $5 / 1048576; w += $2; c += $3 + $4} + END {printf "| **sum** | %.0f | %.0f | |\n", w, c}' "$RESULTS/seq.tsv" + echo + echo "Sizes (MB; objcopied = with the Dockerfile's \`objcopy --compress-debug-sections=zlib\`, gzip = \`gzip -c | wc -c\` of that):" + echo + echo "| | raw | objcopied | gzip |" + echo "|---|---|---|---|" + while read -r name r c z; do + awk -v n="$name" -v r="$r" -v c="$c" -v z="$z" 'BEGIN {printf "| %s | %.1f | %.1f | %.1f |\n", n, r / 1e6, c / 1e6, z / 1e6}' + done < "$RESULTS/sizes.txt" + echo + echo "
each separate binary" + echo + echo "| program | raw | objcopied | gzip |" + echo "|---|---|---|---|" + while read -r name r c z; do + awk -v n="$name" -v r="$r" -v c="$c" -v z="$z" 'BEGIN {printf "| %s | %.1f | %.1f | %.1f |\n", n, r / 1e6, c / 1e6, z / 1e6}' + done < "$RESULTS/sizes-each.txt" + echo + echo "
" +} > "$RESULTS/summary.md" +cat "$RESULTS/summary.md" diff --git a/.github/workflows/measure-split-build.yml b/.github/workflows/measure-split-build.yml new file mode 100644 index 00000000..37849ff7 --- /dev/null +++ b/.github/workflows/measure-split-build.yml @@ -0,0 +1,92 @@ +# Temporary (census #153): on one machine and with the same flags, does +# building the census's pipelines as separate programs, several at a time, +# take less wall time than the one multicall-pipelines binary? Each mojo +# build keeps about two cores busy, so the hypothesis is the same CPU in less +# wall time. +# +# The census's `env` stage (its pixi environment, from Dockerfile.morca at +# CENSUS_SHA) is built on a builder of its own, with GNU time added, and +# .github/measure/split-build.sh runs in a container of it: multicall-pipelines +# as scripts/multicall.sh builds it, then each of its programs alone, one at a +# time and then 4 and 8 at a time, each with an empty Mojo compile cache, and +# the sizes. The results are the job's step summary. +# +# On pushes to this branch only (not pull_request): a push is always this +# repository's own branch, never a fork's, and the PR's own CI doesn't run +# it again. No secrets, and the token can only read. Nothing is pushed. +name: Measure split build + +on: + push: + branches: [image-cache-sai] + paths: [.github/workflows/measure-split-build.yml, .github/measure/split-build.sh] + +permissions: + contents: read + +env: + # census main, on morca-mojo 0.25.0. + CENSUS_SHA: b3eba2d50596672322e06b84010d3dbb7e0ac9ea + +jobs: + split: + if: github.repository == 'morca-dev/morca' + runs-on: [self-hosted, sai] + timeout-minutes: 240 + steps: + - uses: actions/checkout@v4 + with: + path: morca + - uses: actions/checkout@v4 + with: + repository: morca-dev/census + ref: ${{ env.CENSUS_SHA }} + path: census + - name: Build the census's env stage, with GNU time + shell: bash + env: + RUN_KEY: ${{ github.run_id }}-${{ github.run_attempt }} + run: | + set -eu + B="measure-split-$RUN_KEY" + IMG="census-measure-split:$RUN_KEY" + echo "B=$B" >> "$GITHUB_ENV" + echo "IMG=$IMG" >> "$GITHUB_ENV" + lscpu | grep -E 'Model name|^CPU\(s\)' + df -h "$HOME" | tail -1 + cp census/Dockerfile.morca Dockerfile.measure + printf '\nFROM env AS measure\nRUN apt-get update && apt-get install -y --no-install-recommends time binutils && rm -rf /var/lib/apt/lists/*\n' >> Dockerfile.measure + docker buildx create --name "$B" --driver docker-container > /dev/null + docker buildx build --builder "$B" --load --progress=plain --target measure \ + -f Dockerfile.measure -t "$IMG" census > env.log 2>&1 || { tail -80 env.log; exit 1; } + tail -5 env.log + docker image ls "$IMG" --format '{{.Repository}}:{{.Tag}} {{.Size}}' + - name: Measure + shell: bash + run: | + set -eu + mkdir -p results + echo "load before: $(cat /proc/loadavg)" + docker run --rm --name "$B" \ + -v "$PWD/census:/census:ro" -v "$PWD/results:/results" \ + -v "$PWD/morca/.github/measure/split-build.sh:/measure.sh:ro" \ + -e CENSUS_SHA -e HOST_UID="$(id -u)" -e HOST_GID="$(id -g)" \ + "$IMG" bash -c 'cp -a /census/. /src/project/ && cd /src/project && pixi run --frozen bash /measure.sh' + cat results/summary.md >> "$GITHUB_STEP_SUMMARY" + echo "Run on $RUNNER_NAME." >> "$GITHUB_STEP_SUMMARY" + - name: Remove the builder and the image + if: always() + shell: bash + run: | + docker rm -f "${B:-none}" > /dev/null 2>&1 || true + [ -n "${B:-}" ] && docker buildx rm "$B" || true + [ -n "${IMG:-}" ] && docker image rm "$IMG" > /dev/null || true + df -h "$HOME" | tail -1 + - uses: actions/upload-artifact@v4 + if: always() + with: + name: split-build-results + path: | + results/ + env.log + retention-days: 7