Skip to content

Instantly share code, notes, and snippets.

@smoser
Created March 13, 2014 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoser/9536106 to your computer and use it in GitHub Desktop.
Save smoser/9536106 to your computer and use it in GitHub Desktop.
test 2 different base images to compare behavior / performance
#!/bin/bash
## images were created with something like this:
## mv trusty-server-cloudimg-amd64-disk1.img img.dist
## qemu-img convert -O raw img.dist disk-patched.img
## qemu-img convert -O raw img.dist disk-unpatched.img
## sudo mount-image-callback -v disk-patched.img -- \
## sh -c 'cp debs/* $MOUNTPOINT/tmp &&
## LANG=C chroot $MOUNTPOINT sh -c "dpkg -i /tmp/*.deb" &&
## rm $MOUNTPOINT/tmp/*.deb'
NUM_RUNS=${NUM_RUNS:-10}
LOG="out.log"
rm -f "$LOG"
i=0
copyout=(
/var/log/boot.log
/var/log/my-dmesg.log
/var/log/cloud-init.log
/var/log/cloud-init-output.log
)
cat > user-data <<EOF
#cloud-config
password: passw0rd
chpasswd: { expire: False }
ssh_pwauth: True
power_state:
mode: poweroff
message: "Bye Bye"
runcmd:
- ['sh', '-c', 'dmesg > /var/log/my-dmesg.log']
EOF
cloud-localds seed.img user-data
perms="$(id -u):$(id -g)"
while i=$(($i+1)) && [ $i -le $NUM_RUNS ]; do
echo "---- $(date) $i ----" >> "$LOG"
for r in patched unpatched; do
qemu-img create -f qcow2 -b disk-$r.img disk1.img
slog=$(printf "serial-%s-%02d.log" "$r" "$i")
blog=$(printf "boot-%s-%02d.log" "$r" "$i")
pre=$(printf "files/%s-%02d/" "$r" "$i")
mkdir -p "$pre"
echo "---- $(date) $i $r ----" >> "$LOG"
sstart=$SECONDS
kvm -net nic -net user,hostfwd=tcp::2222-:22 \
-drive file=disk1.img,if=virtio -drive file=seed.img,if=virtio \
-serial "file:$slog" -vga none -nographic
ret=$?
echo " $i $r: $ret [$(($SECONDS-$sstart))s]" >> "$LOG"
sudo mount-image-callback disk1.img -- \
sh -c 'd=$MOUNTPOINT;
pre=$1; shift;
perms="$1"; shift;
for f in "$@"; do
out="${pre}${f##*/}";
[ -e "$d/$f" ] && cp "$d/$f" "$out" ||
echo "NA" > "$out";
chown $perms "$out";
done' -- "$pre" "$perms" "${copyout[@]}"
done
done
echo "--- $(date) FINISHED ---" >> "$LOG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment