Collective Warmup
collective.warmup has been created to warm up web application's caches upon start and restart.
It works by reading a configuration file containing a list of urls that are then invoked.
collective.warmup is inspired by Gil Forcada's warmup_plone.py script.
While the basic use case is very simple, collective.warmup offers the following extra features:
collective.warmup can be installed in two ways:
To install it (using virtualenv, on a GNU/Debian machine):
$ sudo apt-get install build-essential python-dev python-lxml python-virtualenv libxml2-dev libxslt1-dev $ virtualenv warmup && cd warmup && souce bin/activate (warmup) $ pip install collective.warmup
and launch it with:
(warmup) $ bin/warmup <path/file.ini>
To integrate collective.warmup in a buildout with Plone, add this to your configuration:
[buildout] ... parts = ... warmup [instance] ... eggs += collective.warmup [instance] environment-vars += WARMUP_BIN ${buildout:directory}/bin/warmup WARMUP_INI ${buildout:directory}/warmup.ini WARMUP_HEALTH_THRESHOLD 50000 [warmup] recipe = zc.recipe.egg:scripts eggs = collective.warmup
After executing the buildout you will find the warmup script in the bin directory.
In this example, the script will be executed automatically by the Zope instance each time it is started.
This is a sample warmup.ini configuration:
[warmup] enabled = True sleep = 2 base_url = http://localhost logfile = /path/to/warmup.log urls = Home page [config] max_attempts = 2 base_path = mysite [Home page] path = ${config:base_path}/ max_attempts = ${config:max_attempts} check_exists = Welcome check_not_exists = p0wned by follow_links = True ignore_middle = @@ ++theme++ # ? ignore_end = .css .js .png .jpg .jpeg .gif .xml RSS .ico
In order not to mark backend healthy too early by the load-balancer, before proper warmup, this package defines a browser view called @@health.check which can be used within your load-balancer probe mechanism. See bellow a Varnish configuration example:
backend instance_1 { .host = "localhost"; .port = "8081"; .probe = { .url = "/health.check"; .interval = 5s; .timeout = 1s; .window = 5; .threshold = 3; } }
This way Varnish will mark the Zope instance backend healthy when ZODB cache-size is bigger than WARMUP_HEALTH_THRESHOLD. If you do not define the WARMUP_HEALTH_THRESHOLD environment variable, the Zope instance backend will be marked healthy as soon as Zope will be able to handle requests.