27

I recently started developing on magento2 new extensions or customizations, and my first impression was a nightmare. I have to wait about 20-30s for every change I make? really?

I'm talking about development mode, I know that in production with cache enabled and other things the website can be smooth. But when I'm working with an extension or layout problem I need to be removing static files, clearing cache, etc.

My question is, how you all M2 developers work? because I don't believe you have to wait 20s-30s for refreshing the page...

My environment: My pc is "good" i5 with 8gb RAM. I need to work with Windows so I use vagrant:

  • Use of all 4 cores CPU
  • Use 5120MB of RAM
  • Ubuntu/trusty64 - Ubuntu 14.04
  • PHP Version 7.0.12-1+deb.sury.org~trusty+1
  • MariaDB - 10.1.18-MariaDB-1~trusty
  • Magento 2.1.2 is installed only with sampledata (no more modules are installed)
  • (Ask me if you wanna know sth more)

What is happenning exactly? Usually M2 responds okay, slow but okay, about 5-10s to load the pages, but sometimes (more usually than sometimes) it just stucks forever! sometimes is the first page and sometimes are the css,js,html files but always the problem is with TTFB.

I saw a problem going to setup wizard too... with angular.js these files lasts forever...

These 2 pictures are about navigating inside setup wizard.

http://imgur.com/Izoyuhj http://imgur.com/Vs5q8eT

Then another one navigating on frontend catalog: http://imgur.com/oXYC52D

What am I asking exactly? Is this normal? you guys work with this timing? I commented this with some colleagues and we just don't believe, I have to be working like this? I sometimes despair of waiting all the time watching the screen...

If someone asks me for show him a test, like creating a new product or something like that he just freaks out... Creating a new order, filling the fields and every field executes a js that lasts for 5-6s...

I don't know but I feel so bad developing with this stuff...

8
  • Haven't had the chance to play with magento 2: but id assume that most of the performance issues comes from your vagrant environment. Do you use virtualbox with vagrant or something else. Using multiple cores with virtualbox degrades performance. Do you run the magento from a shared folder on the vagrant > magento writes files back to the same share you get performance issues. Commented Oct 18, 2016 at 12:03
  • Also you also might be running out of memory on your system what leads to using swap on the host if you give the vagrant 5gigs. only increase the amount if you actually need it. Commented Oct 18, 2016 at 12:08
  • A big part of your problem is that you are on Windows. I was on Windows for years and it was super slow with vagrant/magento. This is because of the file synching mode, its not up to par with nfs. I started dual booting into Ubuntu desktop and my magento sites were very fast, then a while later I got a mac, which uses NFS, and it is also very fast. Commented Oct 18, 2016 at 13:04
  • Yes, it's vagrant with virtualbox. Why using more cores have to degrade performance? I assume giving all resources to VM may be slow "my pc" but faster my VM... And the folder I'm using is /var/www (I tried to not use shared folder, it's only "linux" what is running now). How can I see what is failing? I can execute top, or commands like that.... but don't know how to interpret...
    – Marc Pont
    Commented Oct 18, 2016 at 13:08
  • @ShawnAbramson Yep... we suggested to install dual boot just to try it because as I said we don't believe M2 developers are working like I'm currently doing hehe...
    – Marc Pont
    Commented Oct 18, 2016 at 13:48

15 Answers 15

10

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 no works so fine like this VM.

1
  • I think the major difference to the spec of this VM is memcache? Which, on my Windows (On PHP 7 at least, is not possible)
    – MackieeE
    Commented Dec 14, 2017 at 18:00
6

I found that developer mode disable everything - which was overkill. There's certain aspects I do wish to cache, such as translation. Thankfully in env.php you can still set which caches to use specifically:

'cache_types' => 
      array (
        'config' => 1,
        'layout' => 0,
        'block_html' => 0,
        'collections' => 1,
        'reflection' => 1,
        'db_ddl' => 0,
        'eav' => 1,
        'customer_notification' => 1,
        'target_rule' => 1,
        'full_page' => 0,
        'config_integration' => 1,
        'config_integration_api' => 1,
        'translate' => 1,
        'config_webservice' => 1,
        'compiled_config' => 1,
      ),

This was the above that I chose to cache whilst developing on the Checkout, as this was heavily front-end. I chose to not cache Layout; Blocks and Full page to see my changes.

1
  • Thanks a million! I had this problem, because I upgraded Magento2 to a newer version and did a fresh installation. Apparently it was overwriting my env.php, which made it endlessly slow. This correction to env.php fixed it. Thanks again!
    – codiga
    Commented May 9, 2019 at 12:31
6

disable CSS/JS merging and minifying:

Stores > Configuration > CSS Settings (Javascript Settings) > Merge CSS (Merge JS) > NO

Stores > Configuration > CSS Settings (Javascript Settings) > Minify CSS (Minify JS) > NO

Also see this guide on how to improve Magento 2 performance.

4
  • 1
    The default settings has already these values. And this does not affect so much...
    – Marc Pont
    Commented Jan 17, 2017 at 14:49
  • So would merging be useful on an online server? More overhead towards the processing and not downloading? Commented Mar 2, 2018 at 13:04
  • Why would you disabled CSS/JS Merging and minifying, it's literally an option there to increase speed, this seems to me like shooting yourself in the foot
    – John
    Commented May 22, 2018 at 7:21
  • It's not magic, those speed savings come from somewhere. In this case, you're off loading http requests to PHP code execution when enabled. If the php code is slower than the disk i/o then enabling minifying will be slower.
    – JonShipman
    Commented Feb 7, 2022 at 22:37
4

Suggestions from Magento posted after this question was answered. Reading other answers I think this information could be a helpful addition

http://devdocs.magento.com/guides/v2.2/extension-dev-guide/build/optimal-dev-environment.html

Optimal Configuration

The following is a list of optimizations you can make on your local development machine

  • Magento recommends installing and using the latest supported version of PHP 7 to increase performance.
  • Replace your MySQL database with Percona.
  • Make sure you install and enable PHP OPcache.
  • Xdebug is off by default. Enable this feature only when you need it because it requires a lot of memory and degrades performance. The xdebug.max_nesting_level configuration needs to be set to 200 or greater for Magento. You can increase the memory available to PHP to get an increase in performance with Xdebug on.
  • If you need sample data, you can install it using composer or by cloning repositories.
  • To speed up front end development, turn off merging of CSS and JavaScript.
  • Make sure caching is turned on (this is the default behavior). Generally, only page cache and block cache should be turned off for development and turned back on when testing.
  • Opcache timestamp validation should always be on for development. Development is impossible with opcache on and revalidation off because any PHP modification would require a cache reset.
2
  • For me Opcache did the trick. Its loading quite fast now.
    – Amit Singh
    Commented Jun 25, 2018 at 14:28
  • One other thing I've encountered is Xdebug can be enabled by default which also has a performance hit. Check /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini After changing I think you need to restart the container docker restart {web-container-name}
    – Ian at SSU
    Commented Aug 9, 2018 at 9:06
1

Turn on your cache.

Go to <your magento 2 directory>/bin and run this command magento cache:enable.

Clean the cache when you edit the frontend to see what you've edited.

Go to <your magento 2 directory>/bin and run this command magento cache:clean.

My Reference

I'm new to magento 2 too. I hope someone has a way to make magento 2 fast even when the cache is disabled.

2
  • 1
    Don't know if this is a viable solution... Everywhere it says to disable cache on development mode...
    – Marc Pont
    Commented Oct 18, 2016 at 13:55
  • 10
    Of course if I enable cache, site will go faster... but every change I will have to clean the cache... still a waste of time I think...
    – Marc Pont
    Commented Oct 18, 2016 at 13:57
1

My Setup on Ubuntu 16.10 for frontend development for LESS edits:

  1. Set Developer mode:

    php bin/magento deploy:mode:set developer

  2. Enable all caches:

    php bin/magento c:enable

  3. Fronted Development Workflow set to Server side compilation

  4. After any changes in less files run

    grunt clean

(Last time I menage to start - grunt watch with live browsing and its great)

0

Just want's to share my personal experience, The solution i came up was to install Xampp with php version 7.0 as Magento is not fully compitable with higher version of Php. I tried Bitnami Image listed in answer but doesn't worked as i was expecting Xampp 7.0.23 Download Link

2
  • Really? With xampp is working fine? I tried so many times and it was terrible... What Magento version? Maybe they've fix some performance with this time. I'll try again. And why the Bitnami Image is not working as you expected?
    – Marc Pont
    Commented Sep 25, 2017 at 7:16
  • I have Magento 2.1 and Xampp 7.0 link added above, Comparing Bitnami image to Xampp 7.0 i found xampp easy and faster Commented Sep 25, 2017 at 11:35
0

Increasing PHP memory_limit in php.ini file will make good difference. However it won't make it very very smooth(Although it will save time).

The default value is 512M. On my local machine I set this at "-1"(unlimited) and it gives better loading time.

The recommended value is memory_limit=2G mentioned here.

Magento is heavy and needs high performance hardware like SSD to be smooth :(

6
  • memory_limit has no relation to performance whatsoever. It's obvious from the name of the directive. Commented Mar 15, 2017 at 6:40
  • @DanielV. I was also wondering about that but then I found this: devdocs.magento.com/guides/v2.2/install-gde/prereq/… where it says 2G as recommended value Commented Jan 8, 2018 at 12:34
  • 1
    Again, it is recommended for its own reasons. Which have absolutely no relation to performance. Memory limit is only there to not halt your system completely in case some PHP scripts (or in this case, Magento modules) end up eating all of the server RAM. There is absolutely no performance impact from setting the value too low or too high. It's simply preventive directive to make system more failsafe. And I'm surprised that folks blindly assume that giving more memory for it means performance is achieved through this directive. It's not and never will be. Commented Jan 8, 2018 at 22:08
  • Interesting point, Daniel. I did blindly assume that actually. How can we demonstrate this? Any pointers that you can guide me with so that I can experience this? Commented Jan 9, 2018 at 6:42
  • Set it too low (e.g. 16MB which is surely not enough for M2) and the PHP will fail with fatal error. Install as many modules as you can and set it too high (e.g. 4GB) and things will run OK until you get few more site visitors which will surely cause your server to reach Out of Memory state. You don't need these experiments if you just read the docs for that directive. PHP runs in memory all the time. It doesn't swap to disk or do funny things like that. Commented Jan 9, 2018 at 11:49
0

If your having problems setting up on a Vagrant box, it will almost certainly be how your folders are shared. They should be shared over NFS.

After messing around with lots of different boxes, I realised that although I had set NFS in the config, it was not actually working and the standard VirtualBox sharing system was taking over.

I went back to basics and set up a simple LEMP box and installed this plugin:

https://github.com/Learnosity/vagrant-nfs_guest

Confirmed NFS was working and all was well.

0

Things that can make your Magento 2 setup fast on your local server or in general on any server enviroment.

  1. Minify JS and CSS
  2. Use a caching application like Redis or Memcached.
  3. Enable all the cache like block_html, layout, page_cache etc provided by Magento 2.
  4. Merge CSS and JS
  5. Enable flat products and categories.

Now when on the development enviroment flush only the needed cache instead of flushing the whole cache to prevent the whole rebuild of cache.

0

The main reason why magento2 is slow in developer mode is related to thousand of static and compiled files generated on the fly.

There are 3 solutions for this:

  • Mount whole directory with NFS (SSD is still mandatory).

  • Mount only app directory (whoever your hardware it will work fine) but you lose access to /vendor directory on your host machine.

  • Mount whole project with rsync and exclude directories where files are generated (pub/static, generated/code etc...).

I made that work, give it a try: https://github.com/zepgram/magento2-fast-vm/

0

One thing that can actually cause this is running composer update. It's a documented bug that can reset the cache settings in env.php.

Look for the following settings and make sure they're all set to 1:

    'cache_types' => [
        'config' => 1,
        'layout' => 1,
        'block_html' => 1,
        'collections' => 1,
        'reflection' => 1,
        'db_ddl' => 1,
        'eav' => 1,
        'customer_notification' => 1,
        'config_integration' => 1,
        'config_integration_api' => 1,
        'target_rule' => 1,
        'full_page' => 1,
        'config_webservice' => 1,
        'translate' => 1,
        'compiled_config' => 1
    ],
0

There are few quick steps by which you can increase the website speed please click here to see the answer

0

I am using mac I tried different tools to install magento (xampp,Mamp,vagrant etc) Here i am listing it by the fastest at top. I am discussing about magento development on local environment not running the live website on server.

  1. Xampp for mac. ( The intl library is missing you have to follow the steps https://community.apachefriends.org/f/viewtopic.php?f=29&t=75044 to install it) It is running magento very fast even after enabeling xdebug,(you have to install xdebug 1.X)
  2. Vagrant. Vagrant is a full virtual box environment there are full boxes which contains all the minimum software packages running in a virtual machine you can access it by ip or by a subdomain.
  3. MAMP Pro. Mamp pro is using fastCGI script and its beauty is that you can switch php versions very easily. It has very good interface but when it comes to running magento the performance is very poor.
  4. Bitnami Magento. Bitnami is one click install virtual machine, very fast to install(once click) but unfortunately it is running very very slow.
0

Go to System > Tools > Cache Management in admin panel and scroll to bottom. Then Flush JavaScript/CSS cache and Static Files Cache using the available buttons. Finally click on main "Flush Magento Cache" button.

Worked for me in Magento 2.4.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.