Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 http://example.com/script.php

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
1  
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
show 1 more comment

1 Answer

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
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.