** Description changed: + [SRU] 2.79: https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/2175701 [Impact] - * + snapd catalog refreshes can significantly slow down boot when the store + connection is slow or unresponsive. [Test Plan] - * + 1. Run the following script first with snapd < 2.79 followed by snapd + 2.79 debs: + + #!/bin/bash + set -eu + + # store "proxy" that accepts connections but never answers + cat > /tmp/blackhole.py <<'EOF' + import socket + s = socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(("127.0.0.1", 3128)); s.listen(64) + conns = [] + while True: + c, _ = s.accept(); conns.append(c) + EOF + systemd-run --unit=blackhole --collect python3 /tmp/blackhole.py 2>/dev/null || true + + mkdir -p /etc/systemd/system/snapd.service.d + cat > /etc/systemd/system/snapd.service.d/sru.conf <<'EOF' + [Service] + Environment=https_proxy=http://127.0.0.1:3128 http_proxy=http://127.0.0.1:3128 + EOF + systemctl daemon-reload + + # force a catalog refresh on the next start + systemctl stop snapd.service snapd.socket + rm -f /var/cache/snapd/names /var/cache/snapd/sections + since=$(date '+%Y-%m-%d %H:%M:%S') + systemctl start snapd.socket snapd.service + + start=$(date +%s.%N) + snap set system refresh.retain=$((RANDOM % 3 + 2)) + end=$(date +%s.%N) + elapsed=$(echo "$end - $start" | bc) + echo "snap set took ${elapsed}s" + + # cleanup + rm /etc/systemd/system/snapd.service.d/sru.conf + systemctl daemon-reload + systemctl stop blackhole || true + systemctl restart snapd.service + snap unset system refresh.retain + + 2. Verify the total elapsed time is significantly less with 2.79 (10s of + seconds vs fractions of second) [Where problems could occur] - * - - [Other Info] - - * + The catalog refresh now runs concurrently with the rest of snapd so + errors in locking could introduce new regressions. ---original--- This is a companion to https://bugs.launchpad.net/snapd/+bug/2165972. However it does not seem to be fixed by PR#17626. I've been working on improving Workshop VM launch times, see this draft: https://github.com/canonical/workshop/pull/1042. I found that (at least sometimes) a significant amount of the boot is spent waiting for snapd to refresh the catalog. In my draft I simply create an empty file at /var/cache/snapd/names using cloud-init; this saves about 2s on average (with my NZ internet). Here is a quick reproducer: ``` #!/usr/bin/env bash set -e trap 'lxc delete -f v1 v2' EXIT workaround='#cloud-config bootcmd: - install -D --mode=0644 /dev/null /var/cache/snapd/names ' for vm in v1 v2; do - lxc init --vm ubuntu:24.04 "$vm" - if [ "$vm" = v2 ]; then - lxc config set v2 cloud-init.user-data="$workaround" - fi - lxc start "$vm" - until lxc exec "$vm" -- true &>/dev/null; do sleep 1; done - lxc exec "$vm" -- systemctl is-system-running --quiet --wait - lxc exec "$vm" -- systemd-analyze --no-pager blame - lxc exec "$vm" -- systemd-analyze --no-pager critical-chain + lxc init --vm ubuntu:24.04 "$vm" + if [ "$vm" = v2 ]; then + lxc config set v2 cloud-init.user-data="$workaround" + fi + lxc start "$vm" + until lxc exec "$vm" -- true &>/dev/null; do sleep 1; done + lxc exec "$vm" -- systemctl is-system-running --quiet --wait + lxc exec "$vm" -- systemd-analyze --no-pager blame + lxc exec "$vm" -- systemd-analyze --no-pager critical-chain done ``` In one run, the workaround took snapd.seeded.service from 3.615s to 2.098s. I'm using an Ubuntu 24.04 host with LXD 6.9 and a ZFS storage pool backed by a fast SSD. YMMV. I don't really want to use this workaround, because I think it probably misleads snapd into thinking the catalog was refreshed recently. I just want to move the catalog refresh off the critical path. I think a lot of workshops don't really use snaps, since they can use the equivalent SDK instead, so it's not worth paying the cost of refreshing a catalog that might never be used. I slopped together a couple of patches here: https://github.com/jonathan-conder/snapd/commits/fast12/ which might help with that. I have a more involved reproducer which validates these patches against a baseline of PR#17626 rebased on 2.77.1; see attached. Both patches give roughly similar speed improvements and combining them doesn't seem to have a big impact over just one of them. But I've been running my benchmarks in a noisy environment. I'll leave it to your judgement as to whether either of them is actually a good idea; maybe you can come up with something more suitable.
-- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2167816 Title: snapd network requests slow down LXD VM boot To manage notifications about this bug go to: https://bugs.launchpad.net/snapd/+bug/2167816/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
