Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers

up vote 8 down vote accepted

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.

share|improve this answer
    
One more thing, if you'd like to test only MySQL you can use mysqlslap to autogenerate sql and perform large quantities of sql commands against the server. I've found that this doesn't always come with MySQL so you may need to find it separately. Here is something information on it: dev.mysql.com/doc/refman/5.1/en/mysqlslap.html –  TrueDuality May 14 '09 at 14:20
add comment

Zombat and Frank Farmer have a couple of nice suggestions (I like the slow query suggestion, myself) at Stack Overflow 697802. ab for apache is also quite useful for testing the changes you make.

share|improve this answer
add comment

We run a good size MediaWiki installation and we quickly noticed that MediaWiki benefits greatly from having a memcached instance. Otherwise it has to load up a lot of language files and user data on every request.

share|improve this answer
    
In addition, if you set up memcached correctly, you can serve pages multiple times without making database calls. –  phuzion Jul 27 '09 at 12:25
add comment

Also extremely important is the configuration of the prefork module.. i drastically reduced the numbers in the specific section of /etc/apache2/apache2.conf.. since then i had massive latency, where the page would be stalling for up to a minute before finishing loading... tracing with drupal's trace and devel modules, aswell as profiling with xdebug left me clueless.. i set up APC and modded the MYSQL conf but the culprit actually were the too small values for the prefork module.. i raised those to a moderate AND sufficient level and now the server is back to lightning fast. Watch out for these numbers if you have inexplicable high page execution times....

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
# original values:
#    MaxSpareServers      10
#    MaxClients          150
# far too conservative experimental values:
#    MaxSpareServers       5
#    MaxClients            5
# good compromise:
    MaxSpareServers       10
    MaxClients            20
    MaxRequestsPerChild   0
</IfModule>

These values are for a virtual host environment with 512MiB RAM + 256MiB swap.. good luck finding your server's optimum ;)

share|improve this answer
    
For my server, 1 GB, I have set MaxClients down to 15. As I have a 1 GB server I thought I could handle more then this, however, at MaxClients 25 things go wrong. –  GromBeestje Feb 1 '13 at 15:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.