Warm up Varnish Script using Sitemap.xml

From Brian Nelson Ramblings
Jump to: navigation, search

Warm up Varnish Script using Sitemap.xml

I noticed after doing some random testing on my site that if I do a nightly warming of varnish, my site loads fast with varnish.

I have cache set for about one day, so nightly varnish warming has helped with site speeds.

Here is what I am currently doing:

Create a URL list file

1) Create a list of all urls on the site via the sitemap.xml file

curl --silent http://briansnelson.com/sitemap/sitemap-briansnelsoncom-wiki_-NS_0-0.xml | grep \<loc\> | sed 's/.*<loc>//' | sed 's|</loc>||' > ~/sitemaps/urllist-briansnelson.txt

Now that you have the list of urls on yoru site via the sitemap

Seige your site using the list of urls

Now this kills two objects with one stone

1) It gives a daily report of site performance ...yaaa 2) Warms the varnish cache

You can manually run siege to visually see the results

sudo siege -c100 -d5 -r1 -v -i -f ~/sitemaps/urllist-briansnelson.txt

Setting up Siege to run Via a nightly cron

Now lets set it up as a nightly cron

0 0 * * * /usr/bin/siege -c100 -d5 -r1 -v -i -f ~/sitemaps/urllist-briansnelson.txt

You can run this script as often as you like to keep your varnish cache warmed up, I run my nightly as I do not refreash my cache that often.