alankent / vagrant-magento2-apache-base

Base Vagrant image for building Magento 2 within
58 stars 29 forks source link

Your Vagrant Box is Slow #4

Open maxbucknell opened 9 years ago

maxbucknell commented 9 years ago

The Vagrant box works, but on my laptop is extremely slow. I believe this is most likely due to misconfiguration on my behalf which I will continue to investigate.

I know a thing or two about this, so maybe I can help.

The problem is that you are using VirtualBox shared folders as a syncing method. This is absolutely the worst thing you can do from a performance point of view. I've done a fair bit of research into getting Vagrant to be functional and performant with Magento 1 on Windows, and the bad news is that getting things to be fast is a compromise from VirtualBox shared folders, and the best result depends on your platform, and your preference.

NFS

NFS is a decent choice on non-Windows hosts. You don't get granular permissions, which may or may not matter to you. It requires root privileges to set up, which may or may not matter to you. It doesn't work on Windows, which probably matters to you. It supports symlinks, which is vital for Magento 1, but I hope Magento 2 doesn't need any kind of hack for that.

SMB

SMB seems to be the best choice for Windows based hosts. Unfortunately, it doesn't support symlinks, and suffers from many of the same permission woes as NFS.

Rsync

Rsync is what I prefer, but it comes with a long list of caveats. First off, it's fast, and permissions work perfectly, and it's mostly cross platform, so long as you install CygWin or something else with an rsync client.

The first thing to note is that rsync is not automatic. It requires you to run vagrant rsync after every write. There is a vagrant rsync-auto command, but I find it unreliable, and also that I quite like having control over when syncing happens. Usually I assign a hotkey in my editor. I don't know what your editor is though, so YMMV.

The second thing to note is that it nukes symlinks. With Magento 1, this is a disaster. With Magento 2, you might be okay.

The final nail in the coffin is that Vagrant's rsync is one way. It will not bring changes made on the vagrant box down to the guest. This is a major issue, because it's nice to install Magento on the guest. That's kind of the point. There are solutions. One I like is the vagrant-rsync-back plugin, which on non-Windows hosts can be installed via vagrant plugin install vagrant-rsync-back. This gives a command to sync the other way, and it works well. Installing Vagrant plugins on Windows is a challenge I'm not up to.

But we can sink lower down, and rsync manually. This is where the magic happens. First, you'll want to add Vagrant's SSH key as an identity, so that you can SSH into boxes willy-nilly:

ssh-add ~/.vagrant.d/insecure_private_key

Now we can test this:

ssh vagrant@w.x.y.z

Where w.x.y.z is whatever IP address you assigned to the box you are using. Now, my favourite way to rsync for Vagrant is:

rsync -aHz . vagrant@w.x.y.z:/var/www/magento

or

rsync -aHz vagrant@w.x.y.z:/var/www/magento .

You can alias these commands to things if you want. I have some bash functions that let me just pass in a host and it runs these commands, but the essence is here. I generally find this to be a more helpful and less limiting solution than Vagrant's rsync offering.

And, it's greased lightning. Try it out for yourself. I haven't given any pull requests, because you should experiment with these settings and find what works best for you.

Hope this helps.

jonpday commented 8 years ago

unfortunately Magento2 does use symlinks, so SMB and rsync are both out :( seems like Windows hosts are impossible...