I'm looking for a way to monitor the system resources (CPU, memory, Disk I/O, etc) used by the PHP engine on a linux machine. I can't monitor it by the usual means (top, etc),
since it runs as part of the apache process(es).

Does anyone know of software that can do this? For example, perhaps some kind of apache module or zend utility? I couldn't find anything on php.net, and google has failed me as well, turning up nothing useful for "php resource monitor".

Thanks, any help would be appreciated.

    Well, for a start, you should run benchmarks against an otherwise idle test machine. This machine will of course, be doing NOTHING else, so you can accurately measure the resources required by PHP alone.

    Disc I/O is a tricky one, as you really need to see the big picture - if you're using an external database (e.g. anything except sqlite) most of the I/O will probably be done by the database process(es). You can measure this reasonably accurately if you have a separate database server, but not easily otherwise.

    The amount of IO required will of course vary depending on the amount of available memory (due to caching) - so you will need test boxes with the same RAM as the production machines.

    I can forcast that in all likelihood, on a web application server running PHP as its only server-side code (and no local database processes or other major services), PHP itself will be consuming all most all of the processing time - web server time for other tasks will probably be negligible.

    If you need to monitor individual requests, either configure apache to time them (you can do this in microseconds using the standard Apache logging mechanism) or use a PHP profiler (e.g. APD) or ad-hoc profiling kit (e.g. call microtime a lot)

    Mark

      The issue we have is that we're running several (about 8-10) webservers all load balanced, with static content, PHP, Perl, and mod_jk, among other things I don't recall off the top of my head.

      Basically, I was hoping something already existed that could, from within apache, measure all resources used by the PHP instances within the apache children...Its starting to look, though, like I may have to write my own...

        Can you simulate a reasonable production load in your test environment?

        It strikes me that this sort of thing would be vastly easier to do in a test environment than trying to instrument production (aside from the obvious dangers of instrumenting a production environment - which are greatly mitigated by having load balanced servers).

        As far as memory allocation is concerned, you could build the Apache / PHP with a memory allocation debugger library to see where the memory allocations are coming from - this is probably something you shouldn't do in production (it will increase memory usage and decrease performance).

        I believe that such libraries allow you to instrument memory usage based on where it was allocated- but this might prove problematic if all these different components allocate their memory from Apache's pool allocation system.

        Mark

          Write a Reply...