8

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
Nanocom
  • 3,696
  • 4
  • 31
  • 46

4 Answers4

12

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.

Community
  • 1
  • 1
Nanocom
  • 3,696
  • 4
  • 31
  • 46
  • Good find. I believe the ``file_exists()`` and ``filemtime()`` is to check if the config has changed. Is there a way to prevent these calls and clear the cache manually like in sf1? – Kevin Bond Jan 12 '12 at 17:23
  • 1
    Yes there is, of course in production there is no such calls, but the interesting thing is the difference between Windows and Linux with development environment. – Nanocom Jan 13 '12 at 13:01
6

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

Strayer
  • 3,050
  • 3
  • 30
  • 40
  • 1
    A colleague discovered that WinCache overrides some PHP functions and reimplements then in a windows-optimized behaviour - file_exists is one of them: http://www.php.net/manual/en/wincache.reroutes.php – Strayer Feb 28 '12 at 18:06
  • It is worth noting that WinCache applies *only* when using IIS. – Nikola Petkanski Dec 05 '13 at 14:21
  • 2
    Uhh, no? I was using nginx with PHP over fastcgi in my tests. – Strayer Dec 05 '13 at 15:13
2

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

mblaettermann
  • 1,916
  • 2
  • 17
  • 23
  • 1
    Who runs em? People who develop under windows, maybe? You'd be surprised how many of us there are ;) Me personally: windows at home, linux at work. Anyway I think you're mostly right, this has a great deal to do with either PHP or Apache under Windows. – Eduard Luca Apr 07 '13 at 14:33
  • Some developer has to use windows in order to fit to the rules of the company. – Alexandre Nov 25 '13 at 10:59
1

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

webda2l
  • 6,686
  • 2
  • 26
  • 28
  • 1
    It's already done, but used only in production : in dev environment, the "Debug" loader is autimatically used instead. My question is just : why windows is slower than linux? – Nanocom Oct 18 '11 at 13:26
  • @Nanocom seriously? It's known that linux is better and faster than windows for ages. It simply is. – Eduard Luca Apr 07 '13 at 14:34
  • You won't make me believe that fle_exists and filemtime is really 50 times slower on windows than on linux. – Nanocom Apr 08 '13 at 19:59