Status module – cache expiration, invalidation & poisoning

Hi all,

I have a website thats heavily cached or intended to be heavily cached
via Nginx .

But somehow looking at the page response time I feeling there is a very
high eviction/invalidation rate.

Now is there way I can look at the cache status in Nginx for different.
I
dont use the purge module.

The only way I check cache status is through

add_header X-Cache-Status $upstream_cache_status;

I want to o/p the cache status to a RRD tool and look at the metrics.

Is this possible?

On 14 Out 2012 20h11 CEST, [email protected] wrote:

The only way I check cache status is through

add_header X-Cache-Status $upstream_cache_status;

I want to o/p the cache status to a RRD tool and look at the
metrics.

Is this possible?

With Lua shouldn’t be that difficult. You just inspect the value of
$upstream_cache_status.

ngx.var.upstream_cache_status paired with
http://wiki.nginx.org/HttpLuaModule#ngx.location.capture
to use a specific location to write to RRDtool.

Just an idea,
— appa

On 14 Out 2012 21h06 CEST, [email protected] wrote:

Hi Antonio,

Can you help me a bit more? I have never written in lua

Say for every hit I want to hit a rrd proxy like this

echo “$location_url:1” | nc -w 1 -u host.com 8125

This is not the ideal option because AFAIK (agentzh can chime in to
clarify things) the adding of the data to RRDtool will “hang” your
reply.

Ideally you should have a “frontend” location that issues two
subrequests one to write to RRDtool and another to get the response. I
don’t think that in this particular case it will be dramatic. Try it
and see if you can live with it.

how do I go about doing this in lua?

Try:

location /whatever-is-your-location {
header_filter_by_lua ’
if ngx.var.upstream_cache_status == “HIT” and os.execute("echo "
… ngx.var.location_url … “:1 | nc -w 1 -u host.com 8125”) == 0 then
ngx.header[“X-RRDtool”] = “YES”
end
';
}

This adds a header X-RRDtool if successfull. I stress that this is not
the most performant way to do this. The Lua module can create sockets,
so the best option would be to use that facility and get rid of netcat
IMO.

This is more of a hack than aything else. Perhaps is performant enough
for your application.

YMMV,
— appa

Hi Antonio,

Can you help me a bit more? I have never written in lua

Say for every hit I want to hit a rrd proxy like this

echo “$location_url:1” | nc -w 1 -u host.com 8125

how do I go about doing this in lua?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs