Wednesday 13 May 2009 7:03:34 am
Hello everyone,
Just want to share some things which we discovered. We have a web with nice number of visitor so we plan to use varnish for better performance. Problem is that this web has also non-anonymous users. We want to make varnish cache anonymous only. For testing purposes first we upgrade it to eZ 4.1.1 and compiled varnish 2 from source.
Then we configured everything following: http://ez.no/developer/contribs/documentation/varnish_and_ez_publish_setup_guide
First tests showed that using varnish is much faster of course. On very old and bad PC with virtual ubuntu machine we had about 300 trans/sec (siege test). Also we verified that 'is_logged_in' cookie introduced in eZ 4.1 functions well with varnish configuration.
Problem was that this setup was not functioning well from the client side: after user logs in client web browser starts to cache (it receives cache and max-age headers ) and then if the user logs out browser is showing that cached pages (with user details).
We considered several solutions:
- to make user details with ajax (to much work),
- to rewrite cache headers for client in varnish (to difficult, we are varnish beginners),
- to use s-maxage header (didn't find any information about how varnish support this), but none of them was optimal.
So we finally found rather easy solution:
- on eZ side we disabled all custom headers and use default (let varnish do everything and client will receive no-cache headers) - in varnish configuration we changed order of execution in vcl_fetch like this:
sub vcl_fetch {
# default time to live for cache objects
set obj.ttl = 300s;
if (obj.http.Set-Cookie ~ "is_logged_in=deleted(.*)") {
deliver;
}
if (obj.http.Set-Cookie) {
pass;
}
if (req.request == "GET" && req.url ~ "\.(css|js|gif|jpg|jpeg|bmp|png|ico|wmf|svg|swf|ico|mov|avi|wmv)$") {
set obj.ttl = 600s;
deliver;
}
if (!obj.cacheable) {
pass;
}
deliver;
}
So noncacheable objects are passed but only after we cache anonymous pages and css, js and multimedia stuff. We will test this more, but for now it seems to work very nice. Cheers
http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac
|