Making the zfs snapshot service run faster
By user12625760 on Jan 03, 2009
: pearson FSS 15 $; time /lib/svc/method/zfs-auto-snapshot \\ svc:/system/filesystem/zfs/auto-snapshot:frequent real 1m22.28s user 0m9.88s sys 0m33.75s : pearson FSS 16 $;
The reason is two fold. First reading all the properties from the pool takes time and second it destroys the unneeded snapshots as it takes new ones. Something the service I used cheats with and does only very late at night. Looking at the script there are plenty of things that could be made faster and so I wrote a python version that could replace the cron job and the results , while and improvement were disappointing:
: pearson FSS 16 $; time ./zfs.py \\ svc:/system/filesystem/zfs/auto-snapshot:frequent real 0m47.19s user 0m9.45s sys 0m31.54s : pearson FSS 17 $;
still too slow to actually use. The time was dominated by cases where the script could not use a recursive option to delete the snapshots. The problem being that there is no way to list all the snapshots of a filesystem or volume but not it's decendents.
Consider this structure:
# zfs list -r -o name,com.sun:auto-snapshot tank NAME COM.SUN:AUTO-SNAPSHOT tank true tank/backup false tank/dump false tank/fs true tank/squid false tank/tmp false
The problem here is that the script wants to snapshots and clean up âtankâ but can't use recustion without backing up all the other file systems that have the false flag set and set for very good reason. Howeve If I did not bother to snapshot âtankâ then tank/fs could be managed recusively and there would be no need for special handling. The above list does not reflect all the file systems I have but you get the picture. The results of making this change brings the timing for the service
: pearson FSS 21 $; time ./zfs.py \\ svc:/system/filesystem/zfs/auto-snapshot:frequent real 0m9.27s user 0m2.43s sys 0m4.66s : pearson FSS 22 $; time /lib/svc/method/zfs-auto-snapshot \\ svc:/system/filesystem/zfs/auto-snapshot:frequent real 0m12.85s user 0m2.10s sys 0m5.42s : pearson FSS 23 $;
While the python module still gets better results than the korn shell script the korn shell script does not do so badly. However it still seems worthwhile spending the time to get the python script to be able to handle all the features of the korn shell script. More later.