Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incrementing a Page View Count with Varnish and ESI

If I am using Varnish to cache my entire documents, by what mechanism would you advise I increment a page view count as well.

For example, lets supose that I have an auction listing, such as ebay, and I would like to cache the entire page since I know it is never going to change.

How would you then increase the page view count of this listing.

Lets say that my application is running from Zend Framework. Would it be correct to make an ESI (Edge Side Include) to a node.js server which increments a page view count in Redis?

I'm looking for something that wil be 100% supported and will yielf accurate page view request numbers. (I'm not concerned about duplicate requests either, I"ll handle that in my application logic to prevent one IP from nuking the page view count).

like image 425
Layke Avatar asked Nov 29 '11 09:11

Layke


1 Answers

I would separate your statistics logic from your application. Use a small piece of javascript that requests a resource with a unique timestamp (e.g. an image like /statistics?pageId=3&ts=234234249). You can cache your complete page (no need to bother with ESI) and have the statistics handled by a fast (multiplexing) server like node.js, netty, tornado.

If you need the pageCount in your page, request a small piece of javascript/json data instead of an image and update the DOM in javascript.

This way, you can log better statistics (e.g. dimensions of the page), you minimize traffic and keep statistics a separate concern.

like image 153
ivy Avatar answered Oct 17 '22 23:10

ivy