Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP5 performance comparison, Windows and Linux

I have a question about Symfony2 performance.

I have been developing with Symfony2 under Ubuntu 11.04 for a few weeks now, Apache 2.2.17, PHP 5.3.5, APC 3.1.9, no xDebug

On the dev environment, the time given on the Symfony2 toolbar was never above 70 ms.

Today, I've tried to install my app on a Windows 7 environment : Wampserver 2.2, PHP 5.3.8, Apache 2.2.21, APC 3.1.7, no xDebug

The computer on the windows environment is much better than the one on ubuntu (SSD, Quad core, etc).

And when I run the application on the dev environment, the toolbar indicates always a minimum of 300 ms.

So, do you know how it is possible ?

Thanks !

EDIT : found a link about the subject : http://fossplanet.com/f6/%5Bsymfony-users%5D-symfony2-slow-windows-xp-116465/

I noticed the problem with the file_exists function too (using webgrind).

So, any ideas ?

Maybe the subject has already been discussed, but I was surprised not to find anything related.

like image 977
Nanocom Avatar asked Oct 12 '11 13:10

Nanocom


4 Answers

TL;DR; Set realpath_cache_size to a value > 1000

Edit 2: Problem solved in this PR: Try to set PHP.ini's realpath_cache_size to a value > 1000 A symfony requirement was recently added fixing this issue: https://github.com/sensiolabs/SensioDistributionBundle/commit/cf0179711b24d84d4a29d71a4010540f4c990bd8

Edit: I just saw this answer: https://stackoverflow.com/a/17914570/980547 And it decreased page generation time by 4 on windows when I set realpath_cache_size=4096k in my php.ini (!)

Old answer:

So, I did a comparison between both with webgrind:

On windows (fast computer), called app_dev.php:

Web toolbar

So you can see that the web toolbar shows a 764ms time generation (increased because of xDebug and profiling, but still relevant). Webgrind shows:

  • 651 calls to file_exists() for a time of 232ms (which is a lot!)
  • 603 calls to filemtime() (211ms)
  • 230 calls to UniversalClassLoader->loadClass() (119ms)
  • 230 calls to UniversalClassLoader->findFile() (38ms)

On linux (slow computer), app_dev.php:

Web toolbar

298ms of total generation time (which is more than twice less than on windows).

  • 237 calls to UniversalClassLoader->findFile() (36ms => 4 times less)
  • 237 calls to UniversalClassLoader->loadClass() (20ms => 2 times less)
  • 623 calls to file_exists() (4ms only !!!)
  • 605 callsd to filemtime() (4ms only !!!)

The problem seems to be file_exists() and filemtime(), which are much slower on windows than on Linux. On windows, PHP is looking for files with file_exists, filemtime, loadClass or findFile for 60% of the time. Is that a known problem ?

Edit : so the problem is only for the dev environment, in production no file_exists are done since everything is cached.

like image 64
Nanocom Avatar answered Nov 01 '22 03:11

Nanocom


I just started developing with Symfony2 under Windows and this was a total pain in the ass - I tested xcache, apc and eaccelerator which either made nearly no difference or just crashed when used together with xdebug.

Now I discovered WinCache by Microsoft - which made Symfony2 under Windows unbelievable fast... My requests took something between 1.5s to 3s - with WinCache its down to 200ms. And it doesn't even bother xdebug - profiling and debugging still works like a charm.
Edit: This is all about the dev environment.

The only downside is that it only runs on nts php and I think the apache modules requires ts - if you run it with fcgid though you will have no problems.

I can't believe I worked so many years without this monster...

Links:
WinCache on php.net
Official WinCache site
Binaries

like image 35
Strayer Avatar answered Nov 01 '22 03:11

Strayer


Interesting found!

I would say since this is not a symfony2 issue at all, it has to be fixed in PHP binary..

But who runs his webserver on windows, anyway? :D

like image 34
mblaettermann Avatar answered Nov 01 '22 02:11

mblaettermann


Make a try with ApcUniversalClassLoader http://symfony.com/doc/2.0/book/performance.html

like image 33
webda2l Avatar answered Nov 01 '22 02:11

webda2l