Magento 2 goes terribly slow (Developer mode)

16,544

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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';

Solution 5

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

Share:
16,544
Marc Pont
Author by

Marc Pont

Full Stack Developer. Poker enthusiastic. #Bitcoin

Updated on June 04, 2022

Comments

  • Marc Pont
    Marc Pont almost 2 years

    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 http://i.imgur.com/HG7mbeX.png