2 ms·
Varnish: Counting hits on cached objects
- _cyqui 12y agoHello guys, It's been a long time since i wanted to start a blog, and i just did it. That's my second blog article and aslo the first long one. I Hope you will like it, please comment and let me know whether you liked (or not) Thanks !
- aenum 12y agoAny particular reason why you could not use `obj.hits`? https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHea... (this would be resp.hits in 4.0)
- _cyqui 12y agoNot sure i get the idea, but i suppose it's about adding the hit counts in the response and then query the URL from the backend ? If yes, that's an interesting approach, but in my opinion it has two drawbacks. - It requires a loop through each entities that is supposed to have it's hits counted periodically and query Varnish for it. - There can be hits not counted if for some reason we purge Varnish (not sure about this assertion tho) between two polls. http://cyqui.fr/blog/Varnish-counting-hits-on-cached-objects.html#using-objects-cache-hits http://cyqui.fr/blog/Varnish-counting-hits-on-cached-objects... While with Redis as the counter storage: - We can fetch periodically keys matching 'view_counter_${entity_type}_${entity_id}' (using KEYS command) and it gives a lot of flexibility application side - We do not have to worry about the counters states
- aenum 12y agoIndeed. You would have to poll the endpoints you want to monitor periodically and obviously the hit counter will reset when the object is expired/purged. Something like sub vcl_deliver { if (client.ip == "127.0.0.1") { # or header/method/whatever set resp.http.X-Cache-Hits = resp.hits; } }
- _cyqui 12y agoWill quote this thread in the blog post so that it's more complete by also mentionning this solution (could fit some needs)
- feld 12y agoI noticed in your comment here and once in the article you misspelled "also" as "aslo". :-)
- _cyqui 12y agoThanks for the fix. my english is not perfect and writing will help. Could have check it with some in-app dictionnary tho and will do.