You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@trafficserver.apache.org by "Henry C." <he...@cityweb.co.za> on 2011/10/18 13:15:19 UTC

Trying to understand caching inconsistency with dynamic URLs (or cookies)

Hi,

Using ATS 3.0.1 on CentOS 5.x.
Setup for reverse proxy (ie, as a web accelerator)

I'm having a bit of difficulty understanding the inconsistency in caching
behaviour in my test setup.

I've simplified things down to a single traffic server, and connecting from
three different IP addresses spread across three different subnets.

Basically, what I expect is that if a page is cached, it *must* be served to
any new/same client irrespective of client no-cache, and irrespective of where
the request is coming from, etc.

What I'm seeing though is the following behaviour (say, for URL "test.com/?a=1"):

>From  Hit/Miss  Expecting
----  --------  ---------
IP1:  Miss      Miss
IP2:  Miss*     Hit
IP3:  Miss*     Hit

*=problem

If I repeat the exercise from all three IPs for the same URL then the
behaviour is as expected:

>From  Hit/Miss  Expecting
----  --------  ---------
IP1:  Hit       Hit
IP2:  Hit       Hit
IP3:  Hit       Hit

This has probably something to do with dynamic URLs since the landing page
(http://test.com/ - ie, without '?a=...') is always served as a HIT from the
cache from any IP.  ... or maybe cookies?

My config (I think these are the ones which are relevant):
CONFIG proxy.config.http.cache.http INT 1
CONFIG proxy.config.http.cache.ignore_client_no_cache INT 1
CONFIG proxy.config.http.cache.ims_on_client_no_cache INT 1
CONFIG proxy.config.http.cache.ignore_server_no_cache INT 1
CONFIG proxy.config.http.cache.ignore_client_cc_max_age INT 1
CONFIG proxy.config.http.cache.cache_responses_to_cookies INT 1
CONFIG proxy.config.http.cache.cache_urls_that_look_dynamic INT 1
CONFIG proxy.config.http.cache.when_to_revalidate INT 3
CONFIG proxy.config.reverse_proxy.enabled INT 1
CONFIG proxy.config.url_remap.remap_required INT 1
CONFIG proxy.config.http.cache.cache_responses_to_cookies INT 1

~# traffic_line -r proxy.process.cluster.nodes
1

I must be missing something obvious and would appreciate any pointers.

-- 
Regards
Henry


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by Eric Ahn <by...@gmail.com>.
Wow There is way to process easily, great..

Eric iPhone

2011. 10. 31. 오전 1:34 "Henry C." <he...@cityweb.co.za> 작성:

> On Sat, October 29, 2011 15:59, Igor Galić wrote:
>>> ie:
>>> browserX loads and caches page1. browserY loads page1, but for some reason
>>> the cached page1 is not served.
>>> 
>>> /me wanders off to stare at more HTTP headers, ...
>>> 
>> 
>> Maybe instead of staring at them you might want to share them with
>> us so we can help you :)
> 
> Hi Igor,
> 
> Nothing to do with dynamic URLs...
> 
> It turns out that proxies (ATS included) are respecting some or other RFC to
> identify cache objects based not only on the requested URL, but also on the
> requesting HTTP headers.
> 
> I confirmed this by using several machines and making sure that each was using
> the *exact* same browser user-agent/cache headers.  When I did this, the
> cached object was served up to all the clients, irrespective of who cached the
> object.
> 
> Anyway, I never did solve this problem completely (I didn't need to, luckily)
> - I have a query page which receives requests, it then uses PHP's curl to
> fetch (via the same ats cluster which customers hit) a resource-expensive
> object from back-end servers.  That last request always uses the same
> user-agent/cache headers (curl), so it is *always* the same irrespective of
> the original request from the client who hits our servers from the outside;
> because of this the heavy objects are cached beautifully by ats
> 
> /sidebar:  it would be great if ats had a config option to "normalise" these
> headers so that an object is seen as cached by all clients.  That would
> probably break something or other, I suppose.  However, for our case, it's a
> deal-killer NOT having it.  Fortunately we could work around this limitation.
> 
> Apologies if my description was a bit disjointed.
> 
> -- 
> Regards
> Henry
> 

Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by Leif Hedstrom <zw...@apache.org>.
On 11/01/2011 12:19 AM, Henry C. wrote:
> On Mon, October 31, 2011 23:30, Leif Hedstrom wrote:
>> Well, if you vary: on user-agent, you are almost guaranteed to get a
>> craptacular cache hit ratio. There are thousands (if not 10's of thousands) of
>> variations of User-Agents. It's a real bad idea to vary: on it if you want any
>> sort of cache hit ratio :).
>>
>> I'm stuck doing $work for a while, so haven't had time to get back on
>> mailing lists activities, but just wanted to toss this one in here quickly.
> Thanks Leif - correct me if I'm wrong:  when using a reverse proxy for the
> acceleration benefits, one would think it's a reasonable expectation that
> common objects will be served from the cache to anyone, willy-nilly,
> irrespective of their stupid user-agent string, IP or whether their left cheek
> is rubbing against their right.

Why would you make that assumption? If the origin says that it varies 
the content based on the User-Agent header (or any other header), the 
intermediary (proxy) has no other choice but to try to keep one version 
for every possible string. How else could it work? Intermediaries have 
no way of knowing that even if your origin lies and says Vary: 
User-Agent, it can ignore it. If that is the case, you really (*really*) 
have to modify your origin, not the intermediary.

Just to be clear, the issue is not the User-Agent string, it's that your 
Origin (it seems?) sends a Vary: on these "willy-nilly" headers.

>
> Otherwise, what's the point?

The point is that you have to obey the protocol, if not, you are very, 
very likely to give the wrong document to the users.

-- Leif


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by "Henry C." <he...@cityweb.co.za>.
On Mon, October 31, 2011 23:30, Leif Hedstrom wrote:
> Well, if you vary: on user-agent, you are almost guaranteed to get a
> craptacular cache hit ratio. There are thousands (if not 10's of thousands) of
> variations of User-Agents. It's a real bad idea to vary: on it if you want any
> sort of cache hit ratio :).
>
> I'm stuck doing $work for a while, so haven't had time to get back on
> mailing lists activities, but just wanted to toss this one in here quickly.

Thanks Leif - correct me if I'm wrong:  when using a reverse proxy for the
acceleration benefits, one would think it's a reasonable expectation that
common objects will be served from the cache to anyone, willy-nilly,
irrespective of their stupid user-agent string, IP or whether their left cheek
is rubbing against their right.

Otherwise, what's the point?

There are probably other gotchas in the above scenario, but I ran into at
;east one:  if a page is cached, the language (ie, localisation) of which
depends on a cookie in the user's browser, then the wrong page will be served.
 It was at this point that I gave up (ie, trying to cache everything
irrespective of all user/browser/header issues), and focused instead on forced
caching of the one aspect of my application which desperately needed caching
and didn't depend on user stuff.

Anyway, good times.

-- 
Regards
Henry


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by Leif Hedstrom <zw...@apache.org>.
Henry C. wrote:
> Something else I forgot to mention:
>
> While I was fooling around with trying to isolate what was happening, I
> found
> that if I played around with the Vary header in apache's config:
>
> <FilesMatch '\.(css|php|png)'>
>   Header set Vary "User-Agent"
> </FilesMatch>
>
> ...or unset, I don't recall exactly, then this would also help with the
> situation and common objects would be served to all clients.  However, I
> ran
> into a problem (the details of which I don't recall unfortunately) so
> ended up

Well, if you vary: on user-agent, you are almost guaranteed to get a
craptacular cache hit ratio. There are thousands (if not 10's of
thousands) of variations of User-Agents. It's a real bad idea to vary: on
it if you want any sort of cache hit ratio :).

I'm stuck doing $work for a while, so haven't had time to get back on
mailing lists activities, but just wanted to toss this one in here
quickly.

Cheers,

-- leif



Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by "Henry C." <he...@cityweb.co.za>.
Something else I forgot to mention:

While I was fooling around with trying to isolate what was happening, I found
that if I played around with the Vary header in apache's config:

<FilesMatch '\.(css|php|png)'>
  Header set Vary "User-Agent"
</FilesMatch>

...or unset, I don't recall exactly, then this would also help with the
situation and common objects would be served to all clients.  However, I ran
into a problem (the details of which I don't recall unfortunately) so ended up
not taking this approach.  I even considered hacking the ATS source to *force*
serving of cached objects to all clients irrespective of Vary headers, etc.

Anywho, I'm just documenting this nugget here in case someone else has the
same issue and is looking for things to explore.

h


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by "Henry C." <he...@cityweb.co.za>.
On Mon, October 31, 2011 23:41, Leif Hedstrom wrote:
> Henry C. wrote:
>
>>>
>> /sidebar:  it would be great if ats had a config option to "normalise"
>> these headers so that an object is seen as cached by all clients.  That would
>>  probably break something or other, I suppose.  However, for our case, it's
>>
>
> It *does* indeed have an option to normalize the by far most common header
> used for Vary, which is accept-encoding. For this, it has an option to identify
> "gzip" vs non-gzip, and therefore can deal with the fact that
> there are literally thousands of ways browsers express that they support gzip.

Understood.

-- 
Regards
Henry


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by Leif Hedstrom <zw...@apache.org>.
Henry C. wrote:
>>
> /sidebar:  it would be great if ats had a config option to "normalise"
> these
> headers so that an object is seen as cached by all clients.  That would
> probably break something or other, I suppose.  However, for our case, it's

It *does* indeed have an option to normalize the by far most common header
used for Vary, which is accept-encoding. For this, it has an option to
identify "gzip" vs non-gzip, and therefore can deal with the fact that
there are literally thousands of ways browsers express that they support
gzip.

For the generic case, it's very, very difficult to do something similar.
All i can suggest is to write a plugin for it. Or, wait for us to get the
Lua plugin interface in order (yeah, I know, I suck ...), then it'd be
even easier to just tweak the User-Agent: header accordingly.

Or, don't Vary: on somethng that has so much entropy :). Even if you fix
this on ATS (or varnish or squid), all upstream intermediaries will have
the same problem, and will have a difficult time caching the content
efficiently.

Cheers,

-- Leif



Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by "Henry C." <he...@cityweb.co.za>.
On Sat, October 29, 2011 15:59, Igor Galić wrote:
>> ie:
>> browserX loads and caches page1. browserY loads page1, but for some reason
>> the cached page1 is not served.
>>
>> /me wanders off to stare at more HTTP headers, ...
>>
>
> Maybe instead of staring at them you might want to share them with
> us so we can help you :)

Hi Igor,

Nothing to do with dynamic URLs...

It turns out that proxies (ATS included) are respecting some or other RFC to
identify cache objects based not only on the requested URL, but also on the
requesting HTTP headers.

I confirmed this by using several machines and making sure that each was using
the *exact* same browser user-agent/cache headers.  When I did this, the
cached object was served up to all the clients, irrespective of who cached the
object.

Anyway, I never did solve this problem completely (I didn't need to, luckily)
- I have a query page which receives requests, it then uses PHP's curl to
fetch (via the same ats cluster which customers hit) a resource-expensive
object from back-end servers.  That last request always uses the same
user-agent/cache headers (curl), so it is *always* the same irrespective of
the original request from the client who hits our servers from the outside;
because of this the heavy objects are cached beautifully by ats

/sidebar:  it would be great if ats had a config option to "normalise" these
headers so that an object is seen as cached by all clients.  That would
probably break something or other, I suppose.  However, for our case, it's a
deal-killer NOT having it.  Fortunately we could work around this limitation.

Apologies if my description was a bit disjointed.

-- 
Regards
Henry


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by Igor Galić <i....@brainsware.org>.

----- Original Message -----
> 
> This issue does not appear to be specific to ATS, apologies for the
> noise.
> I've just confirmed that Apache mod_proxy in reverse-proxy exhibits
> the same
> behaviour.
> 
> So, something else is going on here which appears to have something
> to do with
> the Expires header, or cookies, or cosmic rays, or something :)
> 
> ie:
> browserX loads and caches page1.
> browserY loads page1, but for some reason the cached page1 is not
> served.
> 
> /me wanders off to stare at more HTTP headers, ...

Maybe instead of staring at them you might want to share them with
us so we can help you :)

So long,
i

-- 
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/
GPG: 571B 8B8A FC97 266D BDA3  EF6F 43AD 80A4 5779 3257

Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by "Henry C." <he...@cityweb.co.za>.
This issue does not appear to be specific to ATS, apologies for the noise. 
I've just confirmed that Apache mod_proxy in reverse-proxy exhibits the same
behaviour.

So, something else is going on here which appears to have something to do with
the Expires header, or cookies, or cosmic rays, or something :)

ie:
browserX loads and caches page1.
browserY loads page1, but for some reason the cached page1 is not served.

/me wanders off to stare at more HTTP headers, ...


Re: Trying to understand caching inconsistency with dynamic URLs (or cookies)

Posted by "Henry C." <he...@cityweb.co.za>.
btw, the online doc at http://trafficserver.apache.org/docs/v2/admin/http.htm
mentions:

  proxy.config.http.cache_urls_that_look_dynamic

but records.config names it as:

  proxy.config.http.cache.cache_urls_that_look_dynamic

neither make a difference in my case.