Linux – Profiling Apache+Mysql+Php server – which is the bottleneck

lamplinuxoptimizationPHP

How do I profile an Linux + Apache + Mysql + Php server for speed?

I have a server with a heavily modified MediaWiki instance running on Ubuntu 8.04. It's a bit sluggish – I haven't done anything to optimize it yet so I'm sure there is plenty of low-hanging fruit to make it quite a bit faster.

But in order to optimize you need to measure first. How do I find out which of the components (Apache, Php, Mysql) take up the biggest chunk of time to serve a page?

Best Answer

Well when your profiling anything like this to find the bottleneck you need to rule things out one by one. You'll need a baseline to get comparisons against. If you have the "ab" tool installed (it comes with apache) you can use this.

To get your baseline I recommend getting the average of at least a couple of hundred requests. Here's an example:

$ ab -n 400 http://yousite/

Look through the results for the line of "Time per request", it'll look something like:

Time per request:       96.031 [ms] (mean)

Make note of that time as this is the baseline.

To rule out apache as the culprit make a static page on your server (just save the html of a page that you consider slow/sluggish) and run ab against it again.

Throw some PHP into the static page. It doesn't have to be a large amount of it but it should be actually doing some work. MediaWiki is pretty good code so if there is a PHP bottleneck on your system my money would be on the actual loading of the PHP stack into memory and perform the test again.

Look at the three numbers and see where the biggest jump is between the next step up. My bet would be on MySQL being the slowest of the three but it could very well be that you are loading up a lot of images on a page that is slowing down the total request time in which case you might want to rethink the design of the page.

Related Topic