What is the best way to avoid the overhead generated by executing many INSERT queries for logging purposes in a PHP/MySQL application? So far I have narrowed the solutions down to:
- Using the INSERT DELAYED statement. I have a suspicion this will actually be slower, considering there will be many writes and few reads to queue and merge them behind.
- Using a cache module supporting write-behind. However, it seems like there is no such module for PHP. This is also discussed here, though the answers are 3 years old and new technology has emerged since then: How to implement background/asynchronous write-behind caching in PHP?
Not losing log entries is important.
Use the
archiveengine for the log tables.It’s optimized for the workload of keeping a log.
http://dev.mysql.com/doc/refman/5.0/en/archive-storage-engine.html
Note that this engine does not support indexes which speeds up inserts, but slows down selects.