Purging in varnish.
0 Comments Published October 20th, 2011 in linux, monitoring, Open Source, performance, PHP.You might already know varnish. Its a so called website accelerator. It will sit in front of your web server as a reverse proxy, listening on port 80, handling static contents based on the configuration files, and pass all dynamic requests to the main web server behind it.
varnish will help alot to reduce request made to web server, for each static files such as images, css, javascript files, which can be handled by varnish through cache. Once you installed it, you will be grateful. The cache will be built up, and you can see significant reduction in number of request to your web server.
You might update your content, and you need the cached content to be reloaded. We call it “purge”. You might not want to restart varnish, as the whole cache database will be reloaded, and need to be built up again. You can just purge a specific content.
For this, you need your varnish to be able to handle purge request.
put these lines into your main varnish config file.
acl purgeable {
"localhost";
"
}
sub vcl_hit {
if (req.request == "PURGE") {
#set obj.ttl = 0s;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
#set obj.ttl = 0s;
error 404 "Not in cache.";
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
return (deliver);
}
The vcl_deliver part is just additional code for debugging, where it will add additional header in http response, to tell the content caching states, either HIT or MISS. You can verify with “Age: ” info as well, which tell how long it has been in cache.
For purging, Alain Kelder wrote an article, Exploring methods to purge varnish cache, using varnishadm, telnet and http request through telnet. Its quite good article, which gives you options to use which method, and a sample PHP code to make it easy to purge.
For my own notes,
#telnet localhost 80
Response:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Request:
PURGE /path/file HTTP/1.0
Host: hostname.com
Thanks
http://giantdorks.org/alain/exploring-methods-to-purge-varnish-cache/
No related posts.




0 Responses to “Purging in varnish.”
Please Wait
Leave a Reply