PHP running very slow on Linode - any way to speed it up?
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
--------------------------------------
| 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 : localdev.thediamethod.com@127.0.0.1
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
#!/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?
@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.
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.
Also, just putting it out there, it's semi ridiculous to compare the processing time between a VPS and a local local machine..
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.