Symfony2.5 slow Initialization time compared to Symfony2.4 - php

I just installed both Symfony2.4.4 and Symfony2.5.1 and set up a hello world page + some basic things I use (assetic js/css management etc). Configuration and setup for both projects are exactly the same.
I noticed that in app_dev the Symfony2.5.1 needs around 1100ms to generate the page, while Symfony2.4.4 only needs around 130ms to generate the same page. Both numbers come from the Symfony debug toolbar.
When I take a look at the profiler's timeline I noticed Symfony2.5.1 uses around 900-1000ms for something called "Initialization time", while with 2.4.4 that only takes 50-60 ms.
Symfony2.5.1
Symfony2.4.4
Does anyone have an idea why it takes Symfony2.5.1 so much longer to initialize the project? I've checked the changelog for 2.5.x but haven't found anything so far. (https://github.com/symfony/symfony/blob/master/CHANGELOG-2.5.md)
Edit: Apparently the 2.5.1 rebuilds the entire dev cache on each page load, while the 2.4.4 does not. Not sure why.
Edit2: Noticed the chromehelper on my mac was running rogue (eating CPU), so I restarted the browser. Afterwards 2.5.1 doesn't rebuild dev cache anymore and load times are similar to 2.4.4. I don't get how it can be related though, how can a rogue browser influence the rebuilding of dev cache? FYI: The 2 projects are running on a virtualbox with centOS on that same mac.

The initialization time difference between both version was happening because Symfony2.5.1 was completely rebuilding its dev cache every time I loaded the page. I 'solved' it by killing off my mac/chrome browser which was running rogue.
After browser restart, 2.5.1 cache behaved the same as 2.4.4, with loading times around 130ms.
How a rogue browser can influence dev cache, I have no clue though.

Related

Impossible to get PHP Yii waiting TTFB time under 2s (with profiling results)

I created Yii2 basic app https://www.yiiframework.com/doc/guide/2.0/en/start-installation but the index.php waiting time (TTFB) always is around 2s, no less, download time is around 43ms and all the other resources of the default app (CSS, JS) are donwloaded withing 10ms (all as observed from Google developer tools), that is fine. I am running everything on my development machine Windows 10 4GHz, 16GB RAM, low resrouce consumption.
I am adding the xDebug profiling results of index.php call: Results ordered by Incl. and Results ordered by Self.
It can be seen that there is no single slow PHP function, though it is shown that 50% of the self-time is consumed by php::fclose my experiments show that commenting out those two lines only marginally improves the situation. So - it is quite hard to rely on xDebug profiling.
I also experimented with commenting out or changing debug settings but such activities give no improvements as well.
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
2 seconds is very big response time for the application without any functionality and running on the local machine with plenty of resources. We have experience that quite complex Yii applications respond in less than 0.5s and that is fine, but 2 seconds is unacceptable time.
I am using XAMP, PHP 7+, Yii 2.0.14, there is issue filed https://github.com/yiisoft/yii2/issues/15776 that 2.0.14 specifically may be slower but issue is not confirmed, as I understand.
I downgraded the same project to Yii 2.0.5 and tried it under XAMPP with PHP 5.6.23 and the performance is excellent. All the index.php request is completed under 100ms (in Yii 2.0.14 / PHP 7+ it took more than 2s).
Another finding - Yii 2.0.13 basic app works fast under XAMPP PHP 5.6, but this same app return page after more than 2s under XAMPP PHP 7.2. So, possibly the performance problems are not due to Yii2.
How to proceed? What other profiling to do? What other settings to change?
I was investigating the same issue and in my case it was related to xDebug.
I'm using Windows 10 for developing, php 7.1.17 and Yii 2.0.15.1 and tested with the yii basic application.
I also tried yii 2.0.14 / 2.0.13 / 2.0.6 / 2.0.5 and there was always a TTFB of +1100ms.
After disabling xDebug in the php.ini the TTFB dropped to 250ms, which is excellent and feels perfectly fine.
Maybe this issue is related to xDebug and happens only while developing, on the production server it should be fine!

Magento 2 goes terribly slow (Developer mode)

Recently I started developing magento 2 projects.
First I tried on Windows with xampp and it was a mess... every refresh page was a nightmare, about 30-40sec to load the page. I read about it, that Windows system files is so slow working with magento because the large structure it has, and the article almmost was forcing you to use linux for developing on magento projects.
The problem is I need Windows for another company apps that only works on Windows, I tried to install a virtual machine with Virtualbox, it improved a bit... but the fact I'm working on a virtual machine pissed me off...
The next solution and I'm working currently, is using vagrant. Okay, I feel good developing on this way but it keeps going slow... 15-20s...
My config on Vagrant is 5120MB (pc has 8GB) and use all my pc 4 cores.
I'm feeling so bad working like this... when I was working on my previous projects, with symfony/Laravel/Codeigniter, was like:
write some lines of code, tab to browser, F5, INSTANTLY see changes.
On M2: write some lines of code, tab to browser, F5, wait... wait... okay now it refreshes the page, but it's not loaded, wait... wait... hmmm almost... okay. No changes but I cleaned the cache... ohhh I guess I had to remove static files too. Go for it... wait again...
God... There's no way M2 goes faster? I'm only asking 5s or something like that... it's just I'm feeling so dumb looking the screen waiting all the time...
For aclarations, I'm only asking for development mode, I tried had to install another project of magento on production mode for testing things faster and then it's okay fluid as hell compared with developer mode... because... omg... just try to do an order workflow again and again...
Well that's all... The only thing I didn't try is using Linux environment on the computer... but it's just the same as using vagrant... I don't understand... how are you developing M2 developers? in special frontend developers... I don't believe they are working the same way as me... waiting 20sec for loading the pages + cleaning cache + removing static files, etc.
Details: I tried everything with vagrant but don't improve, I'm currently on Ubuntu 15.04, Apache 2.4, PHP 5.6 (I tried 7 but still the same) mysql 5.6
This is the network tab:
http://i.imgur.com/HG7mbeX.png
2018 Update, Magento 2.2.4
Vagrant + Windows + Magento2 = disaster. Vagrant + Apple + Magento2 = disaster.
Ubuntu + Magento2 = cooking on gas.
Simple modules, e.g. a widget, take many days more than the expected 2-3 hours and it is not possible to remember what you are doing if it takes a minute to open a page, particularly so if you have to clear caches, compile, upgrade or anything else that should take no-time-at-all.
This I have experienced first hand, from working in an office where the options are Mac or Windows. After spending a whole day trying to change the template directive and failing to make one configuration change in 8 hours, I thought about giving it a go on a linux box to see if I had gone mad or if this Vagrant contrivance is as helpful as that drunken bum sleeping rough in the park down the road.
The aged linux box with anaemic RAM, an old SSD, stock Apache and no fancy cache things completed the task without problem, I was able to switch between developer and production modes effortlessly and get what had taken me days to not do done in minutes.
The work machine was 8th generation i7, the Vagrant setup was very much someone's baby and a lot of time had been spent building the beast. Yet tectonic plates move faster. Vagrant and virtualisation might be fashionable but it is no use for M2 development. In fact I installed M2 and did all the db and vhost setup for it in less time than it takes for a Vagrant box to build.
As for performance, since M2 on a basic linux setup is 10x faster than some clumsy Vagrant effort, it is easy to see where the real speed problems of Magento 2 are. If you fire up Lighthouse in Chrome you will see TTFB is absolutely fine but the performance halves if you minify and merge the JS + CSS. This is because M2 has a megabyte of scripts to download. This is the performance killer. If you are working on a Vagrant box then you will never see this and not have the speed to fix it. By fix it I mean write a proper theme that doesn't have nonsense such as jQuery loading on every page.
For production you need something that scales so you can get the normal speed enhancements going for that, e.g. Redis, opcode caching, Varnish, tweaked php-fpm, tweaked MySQL/MariaDB. If you are developing on Linux then you can test these things on localhost knowing they will work fine on production. With that abomination that is Vagrant you will be dabbling with these optimisations prematurely because you are hoping and praying for a performant machine because you need to get work done. However, in so doing, and with the absence of native speed, you will not get anything done.
If you don't have a spare machine to put linux on then just go to the local tip, get any PC, shove an SSD in it and you are good to go.
This is my recipe for developing themes/modules in localhost for Magento 2.2 and 2.3:
MacBook Pro
Valet Plus (Nginx, MySQL 5.7, PHP7.1 and 7.2 - you can easily switch between PHP versions with valet use 7.1 or valet use 7.2) https://github.com/weprovide/valet-plus
memory_limit set to 4G
Be sure Magento is set to developer mode: php bin/magento deploy:mode:set developer
ALL CACHES ENABLED except FPC. Whenever I need to test a change involving config files, etc I manually delete the content of the var/cache folder or the generated/code folder for DI changes. The cache type that specially slows down everything is the Configuration cache, so it must be enabled or the frontend/backend pages will load painfully slow.
I use Grunt Watch and the Livereload Chrome extension to see my changes to .less files without having to deploy static files with every change. https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/css-topics/css_debug.html
Whenever I change a JS file I navigate to pub/static/[adminhtml/frontend]/[theme]/[locale]/ and delete ONLY the folder where the static file corresponding to the JS file I changed lives in. This prevents me from having to deploy ALL the static files. Magento will regenerate just the static files for the deleted folder saving a LOT of time (be sure to do a hard refresh in your browser every time you delete a static file)
It’s still not a perfect setup but it’s the fastest way I’ve found so far to be productive without pulling my hair out.
I tried everything and the only thing it works is the virtual machine that provides bitnami. https://bitnami.com/stack/magento/virtual-machine
Seriously, I don't know what has this vm, but goes really fast. I tried creating my VM using a fresh installation of Ubuntu, CentOS, etc. But doesn't work so fine like this VM.
If you work in developer mode you need to disable JS/CSS merge, disable xdebug and enable opcache. Feel free to run thes MySQL queries on your dev DB and flush cache. This will increate the site performance in developer mode.
UPDATE core_config_data SET value = '0' WHERE path = 'dev/css/merge_css_files';
UPDATE core_config_data SET value = '0' WHERE path = 'dev/css/minify_files';
UPDATE core_config_data SET value = '0' WHERE path = 'dev/js/merge_files';
UPDATE core_config_data SET value = '0' WHERE path = 'dev/js/minify_files';
UPDATE core_config_data SET value = '0' WHERE path = 'dev/js/enable_js_bundling';
UPDATE core_config_data SET value = '0' WHERE path = 'dev/static/sign';
Try to disable synchronisation with default vagrant sync folder (just comment config.vm.synced_folder in VagrantFile and reload) - it's to slow when need to work with a lot of files...
Also in developer mode will be useful to generate static files:
bin/magento setup:static-content:deploy and ensure that all caches are enabled: bin/magento cache:status
If it don't help you can try Magento DevBox tool based on Docker: http://devdocs.magento.com/guides/v2.1/install-gde/docker/docker-over.html
In "developer" mode, all caches were disabled.That why magento become slow.
I suggest to enable caches by execute command
./bin/magento cache:enable
However, you need to clean cache ./bin/magento cache:clean every time you modify xml files or configurations.
my recipe:
Use *nix as your main OS
Use docker with PHP 7 and Nginx
use gulp for generating css and js (faster than grunt)
use redis and varnish
disable only needed caches
And the most valuable advice - you really need SSD to work with magento2 if you still trying to develop on HDD
p/s Magento 2 more complicated than Symfony/Laravel/CI (M2 consist Symfony
by the way) and can't be so fast as pure frameworks
For production environment:
You must use Redis for handle Cache, Full Page Cache et Session
(http://devdocs.magento.com/guides/v2.0/config-guide/redis/config-redis.html)
You must use Varnish for HTTP cache built in with Magento
(http://devdocs.magento.com/guides/v2.1/config-guide/varnish/config-varnish.html)
You need to set up production Magento mode.
(http://devdocs.magento.com/guides/v2.1/config-guide/bootstrap/magento-modes.html)
You must use ElasticSearch for search engine, EE only
(http://devdocs.magento.com/guides/v2.1/config-guide/elasticsearch/es-overview.html)
You must use PHP 7
You may use MariaDB even if it is not supported by Magento 2.
You must use CSS minification and JS minification and JS bundling (which works only on production mode).
Check the official Magento 2 documentation in order to set up this production configuration.
A bit late here but i think the answer while working on vagrant / docker is mostly that the I/O of files is terribly slow.
My solution was simply do disable the whole shared folder and replace it with a remote project (sftp connection) in PhpStorm. All files are so stored within the virtual machine and don't have to be synced everytime the page needs a reload.
The main benefit of course is, that it is amazingly fast while working on developer mode.
But also there are some minor problems while working with this setup:
You can't run commands straight from your terminal. You have to ssh into your vagrant for running magento2 cli commands.
After running composer updates you may have to download the whole folder again, because in PhpStorm remote changes are not downloaded automatically.
I made this vagrant which allow you to customize mount options and has great performance:
nfs mount or regular mount
directory mount /var/www/magento/app or whole project /var/www/magento
https://github.com/zepgram/magento2-fast-vm
You can work on a fast magento installation and adapt parameters depending on your work practice and your host machine perf.
For example, if your host machine doesn't support NFS option and has bad performance you can mount only app directory which is enough for development.
#Henry's Cat is right. Non linux os + Magento2 = disaster.
If you are not working hard with xmls you can turn on magento cache
bin/magento cache:enable
and use bin/magento cache:clean when you modify something in theses files
or better just disable certain cache types bin/magento cache:disable db_ddl full_page . #Igor Sydorenko is absolutely right, disabling css js merging/minifiying will IMPROVE A LOT developer mode performance.
In order to give flexibility to developers, Magento generates a lot of files. If it runs in production mode, the slowest part is the disk read which can be optimized.
But while running Magento 2 in developer mode, disk read and write operations make it too slow.
I was also experiencing the same while developing Magento 2 applications. My first suggestion is to move to SSD. However, it is not possible for every everyone every time.
It was also not possible for me to install SSD in my high-end laptop with lot of RAM and CPU power.
I found a work around which made my development considerably fast in localhost using Redis cache. Cache cleaning and warming became extremely fast which reduced my waiting time drastically to see the changes. Here is the full article to use Redis cache in localhost with Magento 2.
Ok so i have been working with Magento 2.2.7 from approx 6-8 months . so there are some notes you should consider :
1. use SSD Hard Disk (if possible)
2. configure grunt in magento. it will surely help to make frontend devlopment in magento fast. because grunt helps to compile less file without need of executing s:s:d command.
grunt with magento
3. do not enable xdebug.
4. disable cache only if you are reloading page too many times in a row.
I tried many machines and many configuration like:
Windows 10 - vagrant machine debian
Windows 10 - vagrant machine debian - docker
Windows 10 - vagrant machine ubuntu - docker
Windows 10 - vagrant machine ubuntu
The problem of bitnami machine : not realy easy to be configured for Xdebug
In my experiance the Best one is a vagrant machine for those who want to work on Windows:
https://app.vagrantup.com/certiprosolutions
So use this config on your Vagrant file:
config.vm.box = "certiprosolutions/ubuntu-lnmp"
config.vm.box_check_update = false
# box modifications, including memory limits and box name.
config.vm.provider "virtualbox" do |vb|
vb.name = "Magento 2.3.3 ubuntu ngnix"
vb.memory = 8240
vb.cpus = 2
#vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end
The advantages:
you can switch between many configuration of PHP
(5.6,7.0,7.1,7.2,7.3)
work on many version of Magento in the same environment
A little note. to make xdebug work you should change the configuration of xdebug to that:
[XDEBUG]
zend_extension=xdebug.so
xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_autostart = true
xdebug.remote_handler = dbgp
xdebug.remote_port = 9001
xdebug.remote_host=127.0.0.1
xdebug.remote_log="/tmp/xdebug72.log"
;xdebug.max_nesting_level = 1000

Laravel templates/controllers not updating on save

I'm running a Laravel 4 for a simple app on OS X.
Basically, changes to controllers and templates don't take effect for a long time after I save changes to those files. For example, I add a word to /app/views/index.blade.php, and don't see any change when constantly refreshing my browser for another minute or so. This makes iterative development understandably painful.
I have tried to chmod 777 app/storage/ and all enclosed files, which has no effect. I have also verified this is not a browser cache issue, because it happens (a) in both Chrome and Safari, and (b) regardless of clearing the cache in those browsers. The problem still occurs even when the app is in "local" and not "production" mode.
I should mention that I am running an updated DP version of OS X 10.9 Mavericks. I can't imagine that would have any effect on Laravel, though.
Edit
I tried calling clearstatcache() in start.php to see if that had any effect, and the problem still remained.
This isn't a laravel issues but a PHP 5.5.3 + MAMP. OP Cache is on by default. see this answer for more: Stop caching for PHP 5.5.3 in MAMP
Having the same issue as as autibyte (note: also recently upgraded to Mavericks, but besides File System permissions not sure how this would be impacting) --- but my blade templates no longer seem to be updating. I've tried permissions + clearing out the views folder. No joy.
I was able to fix the issue by uninstalling MAMP (the app package), then installing PHP, Nginx, and MySQL with homebrew. Now all of my templates update, yay! I am pretty sure that the problem lied with the combination of Apache and Mavericks.
I had the same issue and tried for almost 1 hour to fix the problem. All I did was to restart my computer and then everything worked like a charm for me. Some times computers misbehave and the only solution is to restart or do a cold boot.

Magento: all pages keep loading forever

The problem is when I open any Magento page in browser, including /admin, it doesn't load properly and keeps loading forever. No files where changed - yesterday it was working, today it stopped working.
Can anyone recommend how to debug it? And what might be the reason for this?
There are no any errors in logs, php works fine, we tried rebooting server.
Thank you.
there wont be any errors unless you have low server resources, or maybe you have some content from external servers that probably down right now. first quick debug - open page in chrome and inspect element, you will see what slows your page. or you can check top, no IO problems, enough RAM, no processes running with >100% CPU?
rebooting server never fixes your problems. check if you have cache enabled.
not much information here to tell you exactly whats going on.
I recently ran into this problem too. My Magneto 2 site (on Ubuntu 16.04) worked fine one day and then would continuously load the next. Cleaning the cache and deleting/rebuilding static files made it work briefly, but it would go back to not loading the pages within a few clicks... even the admin.
My fix happened to be that the disk was full. I didn't realize it until I went in command line and updated composer which kept giving me a disk full error.
I switched to the desktop on Ubuntu and ran a disk analyzer, which pinpointed exactly where all my space was being used.
gksudo baobab
I didn't have gksu installed, so I had to install it first by typing:
sudo apt install gksu
It turns out I had backups that had not been deleted. Large tar files that I no longer needed.
I hope this helps!
Edited to include which OS I am using.

Configuring APC with Drupal

I am working on a website which is hosted on a VPS with CENTOS 5.4 i686 virtuozzo installed. I have a drupal installation on the server which gets around 100s of authenticated users at the same time.But at a certain point of time the server stopped responding and the site went offline. So, I tried installing the opcode cache - Alternative PHP Cache.
While the rest parts of the server work fine, the Drupal installation crashes as soon as I install PECL APC with the following message
Fatal error:Cannot run code from this file in conjunction with non encoded files in /home/apogee/public_html/2010/themes/zen/zen/block.tpl.php.
Could you please tell me a way to properly configure Drupal to use APC ?
Thanks
niting
I think the error comes from Zend Encoder...if you don't need it installed then uninstall it and see if that fixes things. If you do need it (closed-source module?), then not sure if that and APC can play nicely together...
you must be disable APC on php.ini
apc.enabled=0
APC and Zend Optimizer can't work with together
David Strauss at four kitchens has done some work on getting Pressflow (Performance tuned Drupal distribution) to work well with APC https://wiki.fourkitchens.com/display/PF/Tuning+APC.
With that much concurrent usage it may be worth your while to look into pressflow.
I have a couple of websites using APC and I've never seen that kind of error -- even with the Drupal-based ones.
After a bit of searching, it seems related to Zend Optimizer and/or Encoder (see the last answer on this thread, for instance), and not to Drupal itself.
I suppose you should use either Zend products, or APC, but not a combinaison of both.

Categories