Skip to content

ci: improve execution times for install-slices - #580

Merged
cjdcordeiro merged 12 commits into
canonical:mainfrom
cjdcordeiro:main
Aug 13, 2025
Merged

cjdcordeiro merged 12 commits into
canonical:mainfrom
cjdcordeiro:main

Conversation

@cjdcordeiro

Copy link
Copy Markdown
Collaborator

Proposed changes

This PR replaces #564.
What's in it?

Related issues/PRs

#564

Checklist

Additional Context

Here are the tests and results:

We can use the latter to compare the improvement of the execution times with existing workflows. For example:

  • the "install slices" step takes ~8m here, while it used to take ~58 min

a similar pattern is verified on all other matrix cells of this job, if compared with existing runs of https://github.com/canonical/chisel-releases/actions/workflows/install-slices.yaml. Even when a specif arch/archive is slow, this new workflow still finished execution much faster.

@ROCKsBot
ROCKsBot requested a review from a team July 1, 2025 15:47
@cjdcordeiro
cjdcordeiro requested a review from a team July 4, 2025 10:01
@alesancor1

Copy link
Copy Markdown
Member

This is great, and actually it is a massive gain on time!

I'm curious about what would be the result of this (parallelism) vs concurrency. In theory, concurrency works better for I/O operations so I think ThreadPoolExecutor could work good here (or maybe just asyncio tasks)

In any case, this is massive improvement :)

@cjdcordeiro

Copy link
Copy Markdown
Collaborator Author

This is great, and actually it is a massive gain on time!

I'm curious about what would be the result of this (parallelism) vs concurrency. In theory, concurrency works better for I/O operations so I think ThreadPoolExecutor could work good here (or maybe just asyncio tasks)

In any case, this is massive improvement :)

👍

something that can be experimented later.

@cjdcordeiro
cjdcordeiro requested a review from alesancor1 July 30, 2025 06:30
@cjdcordeiro
cjdcordeiro requested a review from Meulengracht July 30, 2025 08:13

@zhijie-yang zhijie-yang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, and here are some comments from my side.

Comment thread .github/workflows/install-slices.yaml Resolved
@lczyk

lczyk commented Aug 2, 2025

Copy link
Copy Markdown
Collaborator

tested in a real PR here. i've added the parallel build on top of #606 and made a draft pr. i've had to adjust the pipelines a bit and, eventually, ended up cherrypicking install_slices.py into the branch from which i'm making the PR from, but the files are identical to the ones in dcafc48

@lczyk

lczyk commented Aug 2, 2025

Copy link
Copy Markdown
Collaborator

in the future, can you make a branch named something other than 'main' to PR from? (ideally <jira-ticket>/<whatever>, e.g. ROCKS-2300/libgcc-13-14-dev-25.04) it was a bit of a pain to juggle my local branches to check out the pr

@lczyk

lczyk commented Aug 3, 2025 •

Copy link
Copy Markdown
Collaborator

hmmm... if you compare the install times in the CI between the normal version (#606) and the parallel installation test (#607) they take ca. 20min and ca. 6h (timeout) so i think either i've done something wrong in #606, although there is no git diff ... between this pr and #607 install_slices.py, and the only diff in install-slices.yaml is to coax it into running the workflow from the PR branch as opposed to defaulting to canonical/chisel-releases/main

EDIT:

i cannot get to the bottom of this(!) 😕 i've tried to reproduce the installation locally with this script (run from the root of #607). i've limited the CPUs to mimmic a bit more constrained environment of the CI, but i still got the expected result of about 660s with parallel execution and 1980s withhout. less than 3x speedup, but still a speedup, not the drastic slowdown we see in CI. i think the CI is doing some kindof resource sharing between the 14 jobs (7 arch's 2 chisel versions matrix) we're throwing at it, and the context switch with the additional jobs is too much.

EDIT 2:

turns out all was working correctly, just the way i've set up #607 it was installing all the slices as opposed to just the delta. i'll leave the comment as a chain of thought, but not applicable anymore. 👍

#!/usr/bin/bash

set -e

if [ "$1" = "--run" ]; then
    docker run \
        -it --rm \
        -v.:/mnt \
        --cpus 4 \
        --cpuset-cpus 0-3 \
        ubuntu:25.04 bash \
        /mnt/test_install_slices.sh
    exit 0
fi


export DEBIAN_FRONTEND=noninteractive
export TZ=Etc/UTC

cd /mnt
apt update
apt install -yq $(cat .github/scripts/install-slices/deb-requirements.txt)
apt install -yq python3-pip
pip install -r .github/scripts/install-slices/requirements.txt --break-system-packages

apt install -yq golang
go install "github.com/canonical/chisel/cmd/chisel@latest"
ln -s "$(go env GOPATH)/bin/chisel" /usr/bin/chisel

ARCH=$(uname -m)
[ "$ARCH" = "x86_64" ] && ARCH="amd64"
[ "$ARCH" = "aarch64" ] && ARCH="arm64"

# Trim to the first 50 SDFs for testing purposes
SDFS=$(find slices -type f -name "*.yaml")
SDFS=$(echo "$SDFS" | head -n 50)

date +%s > /mnt/start_time.txt

python3 .github/scripts/install-slices/install_slices.py \
    --arch "${ARCH}" \
    --release ./ \
    --ensure-existence \
    --ignore-missing \
    --workers 20 \
    ${SDFS[@]}

date +%s > /mnt/end_time.txt

DELTA=$(($(cat /mnt/end_time.txt) - $(cat /mnt/start_time.txt)))
echo "NEW: $DELTA seconds"

@lczyk

lczyk commented Aug 3, 2025

Copy link
Copy Markdown
Collaborator

so, as an aside, i've been thinking what takes so much time in this CI anyway, and i've managed to speed it up by another 70%, down to about 210s on the test case above, and it never went above 50% CPU usage on any of the cores while previously being nearly saturated (aka, not CPU bound anymore).

we run the validation inside of the chisel on each and every run we do, but we're always using the same release, so we really need to validate it only once. hence the trick is to install chisel like this: 😅

# clone v1.2.0 of chisel
git config --global advice.detachedHead false
git clone --branch v1.2.0 https://github.com/canonical/chisel.git

cd chisel

# remove validation of release
git apply - << 'EOF'
diff --git a/internal/setup/setup.go b/internal/setup/setup.go
index 18f25f0..35ae23d 100644
--- a/internal/setup/setup.go
+++ b/internal/setup/setup.go
@@ -172,10 +172,6 @@ func ReadRelease(dir string) (*Release, error) {
 		return nil, err
 	}
 
-	err = release.validate()
-	if err != nil {
-		return nil, err
-	}
 	return release, nil
 }

EOF

# build chisel
go build -o chisel ./cmd/chisel
ln -s "$(pwd)/chisel" /usr/bin/chisel

rather than doing this ☝️ in the ci though, i would say that this is a strong supporting argument/use-case for a PR to chisel with some kind --skip-validation

@lczyk lczyk left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor suggestions, but code-wise its ok. it works great locally and but i cannot approve before understanding why it failed with #607 builds (maybe its my poor setup). i'd like to see a fixed #607 with demonstrated speedup, or another test branch (now that i think about it, it can literally just be without any slice changes, just with CI change) which shows it will work in the CI.

EDIT: worked it out and fixed #607. we get approx x3 speedup with 4 workers which is what i'd expect based on local experiments. minor suggestions still applicable though.

@cjdcordeiro
cjdcordeiro requested a review from lczyk August 7, 2025 16:21

@lczyk lczyk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed a bunch of stuff in the comments and more work can definitely be done on this part of the CI. as for this PR though, it lgtm! :)

( cla workflow is stuck but actually passed. see #616 )

@lczyk
lczyk requested a review from norrisjeremy August 12, 2025 10:05

@zhijie-yang zhijie-yang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just one suggestion: Sort the import in install_slices.py with isort, as the CI here likes things sorted ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants