Thinner is a utility for purging urls from a Varnish server.
When you are deploying code changes to a server under load, the uncached load can quickly bring down your backend server even with Varnish's grace mode. Often, allowing stale caches to stick around for a while saves both server performance and sanity.
Thinner gives you fine-grained control over wildcard purging, and rolls purges out slowly. Your users will see stale pages from the previous deploy until Thinner has finished invalidating the stale cache at a rate that you set. If you have a bunch of pages you need to invalidate en masse and at infrequent intervals (e.g. deploys, timed remote api updates), but don't want to risk overloading your server, Thinner is for you.
All that being said, Thinner isn't really a solution for observing model changes and purging associated urls. If you have a highly dynamic application, it's worlds better to handle purging via a job server outside of the request-response flow.
Thinner is available via rubygems:
gem install thinner
Thinner has both a library and command-line interface. To use it as a gem you'll first have to configure how it works by calling Thinner.configure. Here's a quick rundown of all of the options available:
Thinner.configure do |config| # Number of urls to purge at one time. These purge requests are fired in quick # succession. Thinner is perfectly capable of killing a Varnish server, by # overloading the worker thread, so be really conservative with this option. config.batch_length = 10 # The amount of time to sleep between purges in seconds. config.sleep_time = 1 # The server address and management port. See: # http://www.varnish-cache.org/trac/wiki/ManagementPort # for details. config.server = "127.0.0.1:6082" # By default, every time you call Thinner.purge! thinner spins off a new # instance of Thinner::Client and terminates any old instances that are # running. If you want to have overlapping instances set this to true. # It's not recommended to have multiple Thinner::Client's running at the # same time. config.no_kill = false # The log file (either a string or file object) to log the current batch to. # Defaults to STDOUT config.log_file = STDOUT end
Once you have the configuration in place call purge! with an array of urls:
# The urls in this array are purged in order, so you'll want to structure it # according to usage. arr << ["/some_route", "/some_route/with.*", "/"] Thinner.purge! arr
Thinner will then fork a background process and purge the urls. You can check the progress of the purge by tailing the log file or with:
varnishlog | grep purge
If ruby's not your cup of tea, Thinner also has a command line interface. Once you've installed the gem run thinner -h to see the available options.
The command line interface accepts a newline separated list of urls via stdin by setting the -e flag. So you'll be able to use the command like so:
cat urls_to_purge.txt | bin/thinner -e
Fixed bug in command line argument parsing.
Initial release.