Clueless on high TTFB

I’ve upgraded to a 2gb RAM linode with 2CPU’s and still experiencing high TTFB. Hosted on Linode Tokyo VPS. I also have setup a new VPS with Linode, also in Tokyo hoping that would change things. No luck so far.

My Setup:
PHP 5.5.9-1ubuntu4.9 (cli)
mysql Ver 14.14 Distrib 5.5.43,
I run ubuntu 14.04LTS of 2gb ram.
2x 2800 MHz Intel(R) Celeron(R) M processor 1.50GHz

Test results of 5sec+ ttfb of 3 or 4 different websites:

Test results on the same VPS always with less than 2sec ttfb:

This is what surprises me - I have 5 websites that all have high TTFB but there’s one website that always has relatively fast TTFB. I have tried different themes, fresh wordpress installs and all 5 seem to result in high TTFB.
W3Cache is activated on all websites and have same configuration as the fast TTFB website. Again, that fast TTFB website is hosted on the same VPS

Apache and PHP setup:
I have turned on PHP cache by:

;opcache.enable=0 to opcache.enable=1 $ php5enmod opcache $ service apache2 restart

KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 HostnameLookups Off <IfModule mpm_prefork_module> StartServers 4 MinSpareServers 12 MaxSpareServers 24 MaxClients 30 MaxRequestsPerChild 3000 </IfModule> <IfModule mpm_worker_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 150 MaxRequestsPerChild 0 </IfModule> <IfModule mpm_event_module> StartServers 2 MaxClients 150 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxRequestsPerChild 0 </IfModule>

I have started several forum posts in the past months on other forums without any luck:

Many thanks

Do the fresh wordpress installs have any customization, themes or plugins or is it literally the default install? Do they all talk to the same back-end database? Is page caching turned on for all of them?

If you have W3TC on all of them you can turn on debugging which will add some comments at the end of the HTML for the base page that gives you timing information as well as cache hit information. That will help you see if it is a problem within the app processing or if it’s outside (in the web server config).

FWIW, I don’t have a lot of luck scaling Apache for PHP. My favorite config is usually nginx with php_fpm and apc (and with W3TC configured to use apc for it’s cache data) and for W3TC to cache objects and database queries as well. Here is a toy site that my kids use that is running on a misc server laying around in my house: (52ms TTFB).

Hi Patrick,

Yes, even fresh wordpress installation would have long ttfb. Therefor after 40+ hours of tweaking I got a bit annoyed. Although this afternoon I was playing around with my /etc/hosts file I found that when I add my “VPS IP + website url + hostname” the TTFB increased significantly for every website I added.
The reason why my one and only “fast” ttfb website was “fast” was because it was the only website in my hosts file. So basically this solved my entire problem of ridiculously long ttfb’s.

Now I don’t know how or why this decreased my ttfb - I think I read somewhere that it does something with DNS. I have read a couple of dozen of articles and never read anything about the hosts file being related to ttfb.

Have you checked opcache is working ( the output of phpinfo() or php --info | grep opcache )?

The secret I’ve found is to cache everything that possibly can be cached. I don’t have experience of linode Tokyo, but do have over many of their other data centres.

Things to check…

  • the database. I haven’t looksed at Ubuntu lately, but the default configuration used to be completely hopeless. There’s a script called that provides a load of info on how that’s working. Does this show plenty of resource available? [ you may need to install bc via apt-get first ]
  • php memory use. What opcache.memory_consumption values are you using, and memory_limit?
  • swap use. This should be zero if at all possible! You can help that by setting vm.swappiness to a low value - say 10 in /etc/sysctl.conf
  • Is DNS resolving quickly? Do you have a local ‘caching nameserver’ in use that the system is set up to interrogate first?

Because most of the database traffic for a website is reading, not writing/updating, use of a database cache ( these days the innodb engine should be used exclusively really, so it’s those caches I’m talking about primarily ) will dramatically speed up a site as info can just be delivered directly from memory.

If you’re having DNS resloution issues, then the system load will be frustratingly low at the same time as your performance. If you run something like top ( I recommend the alternative htop as it provides more info for me at least ), then you’ll be able to see the base loading on the system when you’re looking at your web pages. [ I’ve just read Sp0ck’s post, and I’m duplicating what he’s said in effect ].

I’d say that one of these two may well be at the core of the TTFB problems ( which are 99% certainly infrastructure based ), and once they are fixed, you can look at opcode, etc caching and other performance enhancements. It’s normal to find that the ultimate bottleneck for a PHP CMS based website is the raw CPU power that PHP needs. Once you’re there, it’s time to upgrade!