Avoid excessive disk writes by avoiding PHP errors in your code
Recently a client complained that their site has been suffering from slow downs that were not there before.
Upon investigating the history of resource utilization, we found that memory usage has increased, and at the same time, the load average has increased as well.
To cut a long story short, we found out that initially, the site had neither dblog nor syslog modules were enabled, and they were enabled before the issues started. They started when syslog was enabled.
Normally, this would not be an issue on a normal site. But for this site, there were lots of PHP and module errors that were written to the log, that it did tie the disk.
These error are like so:
purl: Infinite redirect prevented.
Warning: Invalid argument supplied for foreach() in some_module_category_context() (line 539 of .../modules/custom/some_module/some_module.module).
We pointed out these errors to the client, so that they fix their code.
For the meantime, and to test/prove that this is the root cause, we disabled the syslog module.
Upon doing so, memory utilization went down from 13 GB to 4GB. And the load average dropped from 4 to 5, down to a mere 1 to 2.
The graphs show the decrease in CPU, load average and specially disk I/O and memory usage.
CPU graph. Note the height of the green peaks over the week.
Load average graph.
Disk I/O is much less now.
And memory is also less. The daily cycle is caused by the log rotation of the Drupal syslog. Now the usage is much less, and therefore more free memory for file system cache and buffers.
So, if you have a high load average and the site is slow, check if you are writing a lot of data to the disk either via dblog or syslog. That may be your issue.
Is your Drupal site slow?