Symfony2 Slow initialization time

I have Symfony2 running on an Ubuntu Server 12.04 (64-bit) VM (VirtualBox). The host is the MacBook pro. For some reason, I get very long requests in development mode (app_dev.php). I know it slower in dev mode, but I say 5-7 seconds per request (sometimes even slower). On my Mac, I get a request time of 200 ms or so in development mode.

After looking at my timeline in the Symfony2 profiler, I noticed that ~ 95% of the request time is “initialization time”. What is it? What reasons can be so slow?

This issue only applies to Symfony2 in dev mode, and not to other sites that I run in the virtual machine, and even to Symfony2 in run mode.

I saw this (http://stackoverflow.com/questions/11162429/whats-included-in-the-initialization-time-in-the-symfony2-web-profiler), but it does not seem to answer my questions.

+49
performance ubuntu virtualbox symfony
Oct 15 '12 at 23:24
source share
9 answers

I found out the cause of the problem (and it is not Symfony2). For some reason, on the ubuntu virtual machine, the modification times of some files are incorrect (i.e. in the future, etc.). When symfony2 checks this time using filemtime () on its registry, it determines that the cache is not more recent, and it restores it all. I could not understand why he was doing this.

+13
Oct 19
source share

I had 5-30 seconds of responses from Symfony2 by default. Now it is ~ 500 ms in dev environment.

Then I changed the following things in php.ini :

  • set realpath_cache_size = 4M (or more)
  • XDebug disabled completely (test with phpinfo )
  • realpath_cache_ttl = 7200
  • enabled and correctly installed OPcache (or APC)
  • restarted apache to reload php.ini

And voilá, the answers have passed less than 2 seconds in dev mode! Hope this helps.

To: 6779 ms enter image description here

After: 1587 ms

enter image description here

Symfony2 reads classes from thousands of files and a slow process. When using a small cache of the real PHP path, the file paths must be resolved one after another every time a new request is created in the dev environment, if they are not in the PHP real path cache. By default, for symfony2, the realpath cache is too small. In prod, this is of course not a problem.

Cache Metadata:

Metadata caching (e.g. matching) is also very important to further improve performance:

 doctrine: orm: entity_managers: default: metadata_cache_driver: apc query_cache_driver: apc result_cache_driver: apc 

For this you need to enable APCu . It is APC without a bytecode cache, since OPcache already caching operation code. OPcache is built in with PHP 5.5.

---- After: 467 ms ----

(in a prod environment, the same answer is ~ 80 ms)

enter image description here

Please note: this project uses 30+ packages and contains tens of thousands of lines of code, almost hundreds of its own services, so 0.5s works well in the local Windows environment, using only a few simple optimizations.

+116
Jul 29 '13 at 0:54 on
source share

I also need to disable xdebug (v2.2.21) to debug apache2 max download on my macbook. It has been installed using macports:

 sudo port install php54-xdebug. 

When xdebug is turned on, each page ends with the maximum load time, while a fatal error exceeds the maximum time to wait for the departure. When turned off, everything just charges normally at the reasonable expected time. I came to this with MAMP, xdebug is disabled by default, and apache2 is fast as usual. I can change for another debugger that pitti, because xdebug worked fine before.

Configuration:

  • MacOSX 10.6.8
  • macports 2.1.3
  • Apache 2.2.24
  • php 5.4
+4
Mar 12 '13 at 14:54
source share

We have the same problem. Here we have 10 seconds or more for each request. I see if I delete the following lines in bootstrap.php.cache, all times are returned in normal state (298 ms).

 foreach ($meta as $resource) { if (!$resource->isFresh($time)) { return false; } } 

We may have the wrong changes, but we don’t know how to fix them. Does anyone know a solution?

+3
May 7 '15 at 8:30
source share

As stated in https://stackoverflow.com/a/166268/16/12/12/12/12/12/12/12/12/12/12/12/12/test.htm, as stated in https://stackoverflow.com/a/220280/212 , the reason for this behavior may be the settings of the Ubuntu VM. You must synchronize the date and time between the host and the guest OS, as described in https://superuser.com/questions/463106/virtualbox-how-to-sync-host-and-guest-time .

The file modification date changes to the host value when the file is uploaded to the virtual machine via FTP. Therefore, why filemtime () returns the wrong value.

+2
Mar 24 '16 at 12:17
source share

You can move APP/var/cache to /dev/shm/YourAppName/var/cache . But it’s good to have a built-in container in local files also for autocomplete IDE and code verification. In app/AppKernel.php :

 public function getCacheDir() { return $this->getVarOrShmDir('cache/' . $this->getEnvironment()); } public function getLogDir() { return $this->getVarOrShmDir('logs'); } private function getVarOrShmDir($dir) { $result = dirname(__DIR__) . '/var/' . $dir; if ( in_array($this->environment, ['dev', 'test'], true) && empty($_GET['warmup']) && // to force using real directory add ?warmup=1 to URL is_dir($result) && // first time create real directory, later use shm file_exists('/bin/mount') && shell_exec('mount | grep vboxsf') // only for VirtualBox ) { $result = '/dev/shm/' . 'YourAppName' . '/' . $dir . '/' . $this->getEnvironment(); } return $result; } 
+2
May 21 '16 at 8:54 a.m.
source share

I disabled xdebug, and this reduced the boot time from 17s (yes ...) to 0.5 s.

+1
Feb 13 '13 at 13:34
source share

I also had problems with slow page loading in development, which can be very frustrating when you customize CSS or something like that.

After a little digging, I found that for me the problem was caused by Assetic, which recompiled all the assets at every page load:

http://symfony.com/doc/current/cookbook/assetic/asset_management.html#dumping-asset-files-in-the-dev-environment

By disabling the use of the Assetic controller, I was able to dramatically increase the load on the page. However, as mentioned above, this is associated with the cost of recovering your assets whenever you make changes to them (or set the clock on them).

+1
Oct 07 '14 at 2:53 on
source share

In app_dev, all caches and automatic loading start from scratch, and what I found to be slower in dev is orm. I shy away from using orm and focus mainly on dbal because of this, although I probably shouldn't. Orm is used quite a bit in sf2. My guess is that it slows you down in dev. Look at the difference between the configuration of your dev and prod. However, some settings of your dev configurator may make development much more enjoyable and enjoyable. Just try and realize what you are doing. for example, turning off the branch controller and then changing a large number of templates will be frustrating. Your need to clear the cache. But, as you already mentioned, its developer only and when the time comes to live, symfony will accelerate for you.

-2
Oct 16
source share



All Articles