PHP’s XDebug tracing overhead in production

9 Aug

This is a post with some production information I had pending to write… XDebug PHP extension, is a great, open-source debugger and profiler for PHP. It is a good alternative to the commercial Zend server. XDebug besides its profiling capabilities, it adds full stack traces to PHP error messages when enabled (see config. options). These include Fatal Errors and Warnings as shown in the next picture:

XDebug PHP Fatal error trace

It can be used to track down the causes of hard to find Fatal errors. In general, it is recommended to enable it only in development environments, but since it is a mature product and we were testing it as an alternative to Zend Server, we have enabled it in one our production servers to track down hard to find errors. This option dumps the complete trace of the error into the standard PHP error log.
Its output was very useful debugging production errors difficult to replicate, however, after a few weeks in production we noticed that the server that had XDebug enabled was having a higher load average than the rest. All servers have the same hardware specs and software config. The next Zabbix graph shows the load average on the 15 servers for a week. The green line corresponds to the server with XDebug enabled:

XDebug performance in production

In average, this server had 1.5 load average average, while the rest where around 0.8 of load average average. This overhead increases non-linearly as load on server increases (and there are more errors to report). In our case, the server with XDebug got to 15 in load average as a maximum, while the rest where around 5 as a maximum. The RAM memory usage for this server was also higher, as XDebug keeps traces in memory, which can lead to “out-of-memory” errors in PHP.

XDebug is a great tool, an a good alternative for the commercial Zend Server, however it is not suitable for production environments as Zend server is. But, for eventual debugging on low load, it might be just what you need!

Additional notes:
Tested XDebug was v2.1.0