Jump to content

Article Hit Counter - Most Efficient Method


XGCommander

Recommended Posts

Hello all. I'm new to this forum and I was wondering if anyone has any input on a problem I am trying to solve. On my website we get a lot of articles on digg, reddit, and n4g which can seriously bog down our server. I have made a new version of our site that is still in testing. I have made a complete (and very efficient) caching system which eliminates ALL hits on the database when people view the site from the outside.

 

Our authors enjoy (and some features on the site require) seeing the number of hits an article has received. There are only two options (that I know of) to do this.

 

1. Hit the database every time someone views the page

2. Edit a local file every time someone views the page. It would update the database every time the article recaches or it would be on a cron job

 

My gut tells me that option 2 is more efficient on the server. If anyone can give me some input on which of these is better that would be most appreciated. If anyone knows a more efficient way of doing this then that would be even better.

 

Thank you in advance,

Commander

Link to comment
Share on other sites

what would happen when more than one person tries to update the local file? would they be able to open it if someone else has it open in write mode already?

 

I'm not sure about concurrency when writing to file but it seems like this would be a problem.

 

The database on the other hand would handle this no prob and being that the page is cached, only the counter query would run which shouldn't tax you too much?

Link to comment
Share on other sites

what would happen when more than one person tries to update the local file? would they be able to open it if someone else has it open in write mode already?

 

I'm not sure about concurrency when writing to file but it seems like this would be a problem.

 

The database on the other hand would handle this no prob and being that the page is cached, only the counter query would run which shouldn't tax you too much?

 

Yea that does sound like a problem with doing it file-based, though i'm sure there is a way to fix that. The problem is that if 1000 people hit the site in a minute (which is what happens for the 1st minute or two an article hits the front page of digg or reddit) it just totally kills the server with all those database calls. It isn't the query itself, it's firing the DBM.

Link to comment
Share on other sites

isn't the query pretty basic already?

update articles set count = count+1 where article_id = $id

 

I'd say run an ajax call to a db query so it doesn't slow down the page load time for the user.

 

There's a lot more to databases than queries. There are ways to cache queries, there are also things called stored procedures and stored routines.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.