diff options
author | Simon Rettberg | 2024-02-01 11:25:05 +0100 |
---|---|---|
committer | Simon Rettberg | 2024-02-01 11:25:05 +0100 |
commit | 5b345db370fc09cab1bfac29304432c37c3cb75c (patch) | |
tree | 9fe01d2132cfa6ae2094cf088554781f5b4cac37 | |
parent | [config-tgz] Write config download time to dedicated file (diff) | |
download | systemd-init-5b345db370fc09cab1bfac29304432c37c3cb75c.tar.gz systemd-init-5b345db370fc09cab1bfac29304432c37c3cb75c.tar.xz systemd-init-5b345db370fc09cab1bfac29304432c37c3cb75c.zip |
[slx-addons] Optimize addon activation (~1000% gain)
-rwxr-xr-x | modules.d/slx-addons/hooks/s3-setup-addons.sh | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/modules.d/slx-addons/hooks/s3-setup-addons.sh b/modules.d/slx-addons/hooks/s3-setup-addons.sh index 495e3799..5068d2c2 100755 --- a/modules.d/slx-addons/hooks/s3-setup-addons.sh +++ b/modules.d/slx-addons/hooks/s3-setup-addons.sh @@ -57,15 +57,24 @@ setup_addon() { # purge addon-* files rm -f -- addon-* + # make directory struct, replicate owners/perms - should we keep-old-files? + echo "Replicating directory tree in $NEWROOT" + # Doing this once in advance instead of doing a mkdir for each file's parent directory + # every time in the loop below brought us from 3.6s down to 2.2s for VMware + find . -type d -print0 | tar --no-recursion --null -T - -c | tar -C "$NEWROOT" --keep-old-files -x # move all the files over - find . -not -type d 2>/dev/null | while read -r entry || [ -n "$entry" ]; do - entry="${entry#./}" - [ "$entry" != "${entry%/*}" ] && mkdir -p "${NEWROOT}/${entry%/*}" - mv -f -- "$entry" "${NEWROOT}/${entry}" - done + echo "Moving files over" + while read -r entry || [ -n "$entry" ]; do + # Doing the mv in parallel brought us from 2.2s to 380ms for VMware (~850 files), + # but I've no idea if there'd be an adverse effect if we had a lot more files + # to move and we'd spawn thousands of mv processes in parallel... + mv -f -- "$entry" "${NEWROOT}/${entry}" & + done < <( find . -not -type d ) # do it this way so we don't end up with a pipe-subshell + wait # and can properly wait for all the mv processes. # post merge: remove files marked as whiteouts # (e.g. they were removed during the addon installation) + echo "Applying whiteouts" for WHITEOUT in "$NEWROOT/opt/openslx/etc/"*.whiteout; do [ -e "$WHITEOUT" ] || continue while read -r line; do @@ -73,7 +82,7 @@ setup_addon() { done < "$WHITEOUT" done - cd - &>/dev/null + return 0 } active=() |