I have to update a field in the MySQL database on each HTTP request (number of page visits). Sometimes I have to do this for static files also. In the heavy-load environment this can potentially block responses because the MySQL database can perform a single update (per record) process at a time.
I was thinking of
- appending to a file and parse it in the background every X minutes
- writing log records to the MySQL database (special table) and do a
background processing
How would you optimize that?
I’m not convinced by what you’ve said about MySQL – more than one update can happen concurrently.
If you do reach mysql’s concurrency limits, have you considered using a different data store for this information? For example mongodb is very well adapted to these sorts of upsert operations, as it has a wide range of “fire and forget” update operations known as modifiers
For example you can do something like
This would find the pagecounter object with name x and either increment count by 1 (if count exists) or set count to 1. If there was no such page counter, it would create one