PHP running very slow on Linode - any way to speed it up?

I'm having some issues with a site I just recently moved over to a 4GB Linode. The Linode is running Ubuntu 13.10 (GNU/Linux 3.11.6-x8664-linode35 x8664), and the site runs on Apache/2.4.6 with PHP 5.5.3-1ubuntu2.1. The site has basically no traffic at this point, so these results are measuring one visitor, not under load.

There are a few pages that take a very long time to load. The site is built on PHP using ExpressionEngine, and I'm using the CodeIgniter profiler to measure rendering times. Note that the CI profiler just measures PHP server-side execution times, and that's where the problem is, nothing client-side.

On my Linode, the page takes over 6s to render:

Loading Time: Base Classes      0.0064
Controller Execution Time ( Ee / Index )      6.2166
Total Execution Time      6.2233

On my MacBook local dev running MAMP 2.2 with PHP 5.5.3, with exactly the same codebase and database, this page takes just 1s to render:

Loading Time: Base Classes      0.0194
Controller Execution Time ( Ee / Index )      1.0952
Total Execution Time      1.1148

Note that I also have a preview site running on a crappy $5/mo 1&1 shared server, which also renders the page in about 1 second.

At first I thought MySQL config could be the culprit because the page runs a lot of SQL queries, but looking at the profiler, on my local only about 0.2s is spent on SQL queries, and on the Linode only about 0.6s is spent (measured from PHP, so it includes latency). This means a good 5.5s is being spent just on running PHP while not waiting for the database.

I downloaded a basic PHP benchmark script from http://www.php-benchmark-script.com/ and ran it on the Linode and on my local MacBook. Here are the results from the Linode:

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
Start : 2013-12-15 15:17:15
Server : @
PHP version : 5.5.3-1ubuntu2.1
Platform : Linux
--------------------------------------
test_math                 : 19.591 sec.
test_stringmanipulation   : 17.819 sec.
test_loops                : 9.298 sec.
test_ifelse               : 7.727 sec.
--------------------------------------
Total time:               : 54.435 sec.

And here are the results from the MacBook:

--------------------------------------
|        PHP BENCHMARK SCRIPT        |
--------------------------------------
Start : 2013-12-15 16:19:11
Server : [email protected]
PHP version : 5.5.3
Platform : Darwin
--------------------------------------
test_math                 : 3.431 sec.
test_stringmanipulation   : 4.209 sec.
test_loops                : 2.755 sec.
test_ifelse               : 1.786 sec.
--------------------------------------
Total time:               : 12.181 sec.

So my question is: why is PHP 5x slower on my Linode than on my MacBook or my 1&1 shared server, and is there any way to speed it up?

11 Replies

I'm not really a PHP person but I Googled some and put the PHP CLI script below together, it runs on my home machine in around .37 seconds and on my Linode around .11 seconds:

#!/usr/bin/php

 (memory_get_usage() - $mem) / (1024 * 1024),

  'seconds' => microtime(TRUE) - $time

));

?>

Here's my home machine spec, 8 cores:

vendor_id : GenuineIntel

cpu family : 6

model : 58

model name : Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz

stepping : 9

Here's my Linode:

vendor_id : GenuineIntel

cpu family : 6

model : 26

model name : Intel(R) Xeon(R) CPU L5520 @ 2.27GHz

stepping : 5

How fast does your Linode run the above?

Hi jebblue, thanks for your reply. Your CLI script runs on my Linode in 0.27 seconds and on my local MacBook in 0.05 seconds.

@wtravish:

Hi jebblue, thanks for your reply. Your CLI script runs on my Linode in 0.27 seconds and on my local MacBook in 0.05 seconds.

Seems hard to believe a macbook could beat my fast home machine running Linux.

EDIT: I just tried it on my laptop and I get .05. Weird, seems like my desktop would have beaten it, or that's what I'd have thought.

Just for reference, my Linode took .23 and my MacBook Air took .03.

Removing the echo statement changes the times to .0012 for the Linode and .0003 for the MacBook Air.

Removing the SSH overhead for the echo responses does make a difference.

Dave Sand

@dasand:

Just for reference, my Linode took .23 and my MacBook Air took .03.

Removing the echo statement changes the times to .0012 for the Linode and .0003 for the MacBook Air.

Removing the SSH overhead for the echo responses does make a difference.

Dave Sand

Wow, so I ssh'ed into my laptop and got .05 then ssh'ed back to my desktop and run it and I get .05? When I just open the terminal on my desktop directly and run it it's slow at .37.

Making use of php 5.5's opcache might help

http://php.net/opcache

I enabled the OpCache, but it doesn't seem to have made any difference in this case. I actually think it's enabled by default in 5.5, so I might have already been getting the benefit of that.

Perhaps you might contact Linode support to see if there are any performance issues on the host?

I've actually done that as well, but they didn't see any performance issues on the host. I've migrated to a different VPS instance, but it didn't make a difference.

Can you provide access to a phpinfo()? I'm assuming a configuration issue. My linodes are completing the php benchmark script in < 18 seconds. I also have a couple of FuelCMS/CI sites running on one VPS with zero issues. Page loads are instant.

Also, just putting it out there, it's semi ridiculous to compare the processing time between a VPS and a local local machine..

I'm hoping it's a configuration issue. Here's a link to the full PHPInfo: http://thediamethod.com/info.php

I also agree that it's somewhat silly to compare to a local machine, although I'm also seeing much better performance on a shared hosting service. If it just turns out that a VPS is 10x slower than a shared host, so be it. It does seem somewhat fishy though.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct