Page Counters, A different approach...

« previous entry | next entry »
Jul. 1st, 2007 | 10:13 pm

I just noticed PeterZ's post on page counters:
http://www.mysqlperformanceblog.com/2007/07/01/implementing-efficient-counters-with-mysql/

Let me offer a different solution.

Do not do it.

Really, if you grow a site to any size at all you will discover that
the contention you create on updates is just too much. Sure, you can
optimize it by have the update done on a de-normalized table, but
unless you are using 5.1 with its row level replication, eventually
the replication locks will nail you.

Instead build an accesslog type table. You probably already have one,
aka you are recording your accesslog in your database. Just run a job
every so often that updates the counter on your object in its own
table (which will save you on the select if it is useful to have a
historical count on the object).

If you want a simple logger to MySQL, I keep mine here:
http://hg.tangent.org/Krow-Apache-Log/

Link | Leave a comment | Add to Memories | Share

Comments {1}

peter_zaitsev

(no subject)

from: peter_zaitsev
date: Jul. 2nd, 2007 09:04 am (UTC)
Link

Brian,

I'm not sure where exactly you disagree with my post, using access log type table is exactly one of optimizations I mention in my article.

Anyway you can see full reply back in my blog :)

Reply | Thread