Recently we've been having problems with our LAMP setup and we started to see the number of MySQL databas开发者_C百科e 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?
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:
- Close a connection to MySQL if you're done with it, so the connection is released sooner.
- Increase the maximum allowed connections if you really need them.
- If you still have hanging processes, check the output of
SHOW FULL PROCESSLIST
to see what queries are being performed. - 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 toolmysqldumpslow
can accurately group / count the queries.
If you have access to php.ini, you can use Xdebug : http://xdebug.org/
精彩评论