apache2 and php slow first load on Ubuntu VPS - something like mysqltuner but for apache?

Ubuntu 10.10 64 bit VPS, 512Mb dedicated RAM. Mysql tuned so that sqltuner is completely happy. Used RAM never above 350Mb out of the 493 available. Load never exceeds 1.04 or so.

httpd.conf tuned as per all the guides for vps of that memory - amount of preforks, spares etc.

But for the FIRST load a site after having not visited for a while, it's taking ages.

First load: Parse Time: 3.576 - Number of Queries: 50 - Query Time: 0.019723195953369

Reload Parse Time: 0.096 - Number of Queries: 39 - Query Time: 0.0066126374511719

Subsequent reloads will be at this speed.

htop shows two items as soon as I load that page for the first time:

php-cgi /usr/sbin/apache2 -k start

I'm using suPHP but I've tried fast-cgi and cgi.

Stuck now, a weekend of tweaking has brought me nothing. Advice appreciated.


I had the exact same problem on my local server running ubuntu 10.10, LAMP. It was my router configs. Since mine was local I was using dnsmasq to run development sites (website.dev). My router was a DNS relay. Once I turned off DNS relay the problem went away. Once thing to check is the speed when accessing localhost. If that is fast on first load, you probably have to fix your network settings