Mailing List Archive

VCL help needed
I have been using varnish for a particular web blog/forum app, so far
it is working well, except that forum users get confused when they
delete or add a post and do not see the changed page immediately; so
they either double-click (meaning a duplicate post) or try to delete
something that has already been deleted.

In any case, the first rule is "don't confuse the user", so since I
have trained the users to expect one kind of behavior I can't expect
them to automatically adjust to a different behavior.

I ended up commenting out the vcl_fetch routine in the default vcl.conf
and setting default_ttl to 15 seconds on the command line. Basically
this is almost disabling the cache (hits are 10% or so).

Based on my reading, what I think will work best, is to set default_ttl
to a very low value like 5 seconds, then use a regexp to specify
explicitly what should be cached.

This works because what I want to cache are the .css, .gif, .jpg, .swf,
.mp3 files - since virtually all the actual HTML is dynamically
generated out of a database, simply off-loading the delivery of other
files is the key thing I want varnish to do.

e.g. "if filename ends in .gif|.jpg|.css|.mp3 add to cache and set
timeout to 600 seconds" ; otherwise default_ttl at 5 seconds will
expire the page and eliminate double-clicks and double-deletes.

Can I put a regexp in the vcl_fetch routine? Just add something like
this to the stock vcl.conf:

sub vcl_fetch {
if (req.url - "/.css|.gif|.jpg|.mp3|.swf/") {

# force minimum ttl of 600 seconds (mod from orig. 180s)

if (obj.ttl < 600s) {
set obj.ttl = 600s;
}
}
}

I am sure I have the syntax wrong, and the regular expression is wrong;
but I think I am clear on what I am trying to do.

Cordially
Patrick Giagnocavo
patrick at zill.net
VCL help needed [ In reply to ]
In message <65c91d15180d6f5e92000bd1931e8db8 at zill.net>, Patrick Giagnocavo writ
es:

>Can I put a regexp in the vcl_fetch routine? Just add something like
>this to the stock vcl.conf:
>
>sub vcl_fetch {
> if (req.url - "/.css|.gif|.jpg|.mp3|.swf/") {

if (req.url ~ "\.css|\.gif|\.jpg|\.mp3|\.svf") {

If there are no tracker suffixes, it will be faster if you
anchor the regexps to the tail end of the url:

if (req.url ~ "\.css$|\.gif$|\.jpg$|\.mp3$|\.svf$") {

Other than that, yes, it should work just fine.

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
VCL help needed [ In reply to ]
> if (req.url ~ "\.css$|\.gif$|\.jpg$|\.mp3$|\.svf$") {

or with less typage, right?:
if (req.url ~ "\.(css|gif|jpg|mp3|swf)$") {
VCL help needed [ In reply to ]
In message <8591.217.28.163.19.1170153809.squirrel at localhost>, ff at suse.de write
s:
>> if (req.url ~ "\.css$|\.gif$|\.jpg$|\.mp3$|\.svf$") {
>
>or with less typage, right?:
> if (req.url ~ "\.(css|gif|jpg|mp3|swf)$") {

Probably yes, I'm not a RE wizard either :-)

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
VCL help needed [ In reply to ]
On Jan 29, 2007, at 22:16, Patrick Giagnocavo wrote:

> This works because what I want to cache are
> the .css, .gif, .jpg, .swf, .mp3 files - since virtually all the
> actual HTML is dynamically generated out of a database, simply off-
> loading the delivery of other files is the key thing I want varnish
> to do.

Why not just serve the static media from a separate hostname?

On a related note, Cal Henderson wrote a good article about making
css, javascript and image files extra cacheable.

http://www.thinkvitamin.com/features/webapps/serving-javascript-fast


- ask

--
http://develooper.com/ - http://askask.com/
VCL help needed [ In reply to ]
On Jan 30, 2007, at 10:24 PM, Ask Bj?rn Hansen wrote:

>
> On Jan 29, 2007, at 22:16, Patrick Giagnocavo wrote:
>
>> This works because what I want to cache are the .css, .gif, .jpg,
>> .swf, .mp3 files - since virtually all the actual HTML is dynamically
>> generated out of a database, simply off-loading the delivery of other
>> files is the key thing I want varnish to do.
>
> Why not just serve the static media from a separate hostname?
>

The client would rather pay me than have to change all the hard-coded
information in all the places. And there are some other issues with
the way the site is coded that might make it difficult (each user has a
URL of the form username.domain.com) .

Besides we seem to be saving some CPU overhead just in having Varnish
handle the sometimes-slow TCP connections with the users (not all are
on high speed connections).

> On a related note, Cal Henderson wrote a good article about making
> css, javascript and image files extra cacheable.
>
> http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
>

thanks for the link!

--Patrick