Increasingly more sites are exhibiting the amount of sights (and clicks like on dzone.com) certain pages receive. What's the best practice for monitoring view #'s without striking the database every load?
I've got a couple of potential tips on how to do that during my mind but not one of them appear viable.
Thanks, very first time user.
I'd try the database approach first - coming back the need for an autoincrement counter ought to be a reasonably cheap operation so you may be amazed. Even keeping a table of numerous products which to record the hit count ought to be fairly performant.
However the question was how to prevent striking the db every call. I'd suggest loading the table in to the webapp and incrementing it there, only backing up towards the db periodically or on webapp shutdown.
One cheap trick is always to simply cache the worthiness for any couple of minutes.
The precise quantity of sights does not matter much anyway since, on the busy site, within the time a customer experiences the page, an entire batch of recent sights has already been in.
You can setup a set file which has the amount of hits inside it. This could have issues scaling, however it perform.
If you do not worry about exhibiting the amount of page sights, you could utilize something similar to google analytics or piwik. Both make demands following the page has already been loaded, therefore it will not impact load occasions. There can be a method to create a ajax request towards the statistics server, but I'm not sure without a doubt. Piwik is opensource, so that you can most likely hack something together.
If you work with server side scripting, increment it inside a variable. It's prone to get totally reset should you restart the help so not such advisable if precision is required.
One of the ways is by using memcached like a counter. You can modify this rate limit implementation to rather behave as general counter. The important thing might be in yyyymmddhhmm format by having an expiration of 15 or half an hour (based on how you feel to become concurrent site visitors) after which simply
get individuals secrets when exhibiting the page.
Nice libraries for interacting using the memcache server can be found in many languages.