views:

45

answers:

2

Recently we've been having problems with our LAMP setup and we started to see the number of MySQL database connections spike up every now and then. We suspect that some mysql operation is taking longer than usual and apache just started to build a backlog of connections to deal with incoming requests.

Question is, is there a way to per page statistics on things like average load time? median load time? max/min load time for each php page (page1.php, page2.php, page3.php etc). So that we can narrow down where the problem is. Is there such thing included as part of apache? Maybe a separate module?

A: 

If you have access to php.ini, you can use Xdebug : http://xdebug.org/

Loïc Février
+2  A: 

From the log format, you can just log the time taken (%D) in your access logs, and after an incident, sort on time-taken, and check the urls. I'm not aware of any application that checks this out of the box, but a lot of applications can handle apache's access logs, so chances are there are those who can work with it. I seldomly look at page-specific logs, only server totals, so I can't help you there.

If MySQL is busy / the cause:

  1. Close a connection to MySQL if you're done with it, so the connection is released sooner.
  2. Increase the maximum allowed connections if you really need them.
  3. If you still have hanging processes, check the output of SHOW FULL PROCESSLIST to see what queries are being performed.
  4. You can enable the slow_query_log, logging all queries above a certain amount of miliseconds (in newer versions, old versions only supported seconds) or not using indexes. The command line tool mysqldumpslow can accurately group / count the queries.
Wrikken
It's worth noting that although I believe this is the metric the OP should be looking at, %D measures the time for a single URL - not a page, and (IIRC) it measures the time taken between receipt of the request and offloading of the response - which is not the same thing as the time taken to generate the response.
symcbean
If the question was 'how can I get accurate statistics', you would be totally correct. However, the question is only: how can I track down long running processes, for which this is quite suitable.
Wrikken