Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to count impressions of a .php script that is accessed via web. Right now I do this in a 1 line MySQL table and just increment the value. This works fine usually but when the server has traffic bursts (hundreds of requests/second) everything gets delayed and the increment SQL statements start to pop up in MySQL's slow queries log.
I tried to count via APC but it "loses" values, that is, when I run a simple ab test command like

ab -n 100 -c 10

only ~50 new impressions are counted while on MySQL 100 are counted.
I also tried to count impressions via memcache, it works better (that is, its able to keep up with more simultaneous connections) but it also fails to count everything after 50 or 100 simultaneous connections.

I was wondering if there is anybody aware of a good solution to this problem?

share|improve this question
what is wrong with parsing log data after the fact? – n8whnp Jan 15 '13 at 14:33
What does your SQL look like that increments the value? – Eric Petroelje Jan 15 '13 at 15:41
@n8whnp: well, I need the data in real time and also I don't have the logs activated. – Alex Flo Jan 17 '13 at 9:31
@EricPetroelje I am not sure I understand your question? – Alex Flo Jan 17 '13 at 9:31
@Alex - you must have an SQL statement that increments the value in the table. What does that look like? – Eric Petroelje Jan 17 '13 at 13:45
up vote 0 down vote accepted

In the end I chose to use a MEMORY table instead the usual INNODB one. While the solution isn't perfect it works much better than just using INNODB for this. I also applied this solution on a number of other tables where data integrity wasn't crucial and the results were positive.

share|improve this answer

Your Answer


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.