A fascinating story. Increasing the counter, however it may be, just has to be a transaction ... which means that it can lock the entire database for longer than it makes sense! -) It could just be a bottleneck for the whole system.
If you need strictly accurate calculations, but don't need to be updated instantly, my favorite approach is to add counting information to the log (switching logs as often as necessary for data glowing purposes). When the log is closed (with thousands of counting events in it), the script can read it and update everything that is needed in one transaction, perhaps not intuitively, but much faster than thousands of single locks.
Then there are very fast counters that are only statistically accurate, but since you are not saying that such an inaccuracy is acceptable, I will not explain them in more detail.
Alex martelli
source share