Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I received this response from Jeff while researching hit counters. He said page hits are incremented in a buffered write scheme, and that a views table does not exist.

Can you explain what a buffered write scheme is, please? I would appreciate answers not too heavy with technical jargon.

In particular I'm interested in how such a scheme can be implemented to track page hits. I'm curious how hit data gets persisted since it is needed to prevent users from simply refreshing a page to increment page hits.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

In general a buffered write scheme is where a whole bunch of data writes (to disk) are buffered (saved somewhere in memory) and then written out to disk all at once. This is because one big write to disk is less expensive than a whole bunch of little writes because each write has seek time and other overhead.

I think Jeff's answer was pointing out that the view count for each post in the database isn't actually updating in real time, incrementing by one for each view. Instead its updated in memory, and then written out to the database periodically.

share|improve this answer
    
Thanks! When you say a whole bunch of writes, do you mean a bunch of SQL statements? Or just data getting persisted in memory until some function writes it to the database? If so, where would one persist visit data to protect from abuse, as discussed in my last point... ? –  Mohamad Jul 11 '11 at 20:42
    
I think Jeff means that there is some post view counter data structure in memory and it gets incremented once for each view. Every now and then it gets written to the database. –  Shane Wealti Jul 11 '11 at 20:44
    
thanks again. Sorry to drag this out a bit, but I want to get a handle on it. So "a buffer write scheme" doesn't have to be implemented in some specific system, or specific way; it's just a method of doing something, whether it's at the DB level, application level, etc... ? –  Mohamad Jul 11 '11 at 20:50
    
Correct. A buffered write scheme is a general way of doing something--making i/o more efficient. –  Shane Wealti Jul 11 '11 at 20:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.