9

On my windows 7 I use:

  • VirtualBox 5.0.20
  • Vagrant 1.9.1
  • vagrant-share (1.1.6, system)
  • vagrant-winnfsd (1.3.1)

I have an ubuntu vagrant box with some PHP software (piwik) which on a specific CLI command does some processing which involves files. I've measured how long it takes for the command to complete on various types of sharing from guest (ubuntu) to host (win7):

  • 30 seconds on a simple shared folder.
  • 5 seconds on an nfs shared folder (via config.vm.network "private_network", type: "dhcp" and config.vm.synced_folder "piwik", "/web-pub/piwik", :nfs => true, :mount_options => ['actimeo=2']).
  • 0.5 seconds without sharing, after having copied all relevant files under /tmp, which is not shared.

I confirm proportionally similar numbers on different tasks (e.g drush cc all on a vanilla drupal 7 installation).

Do you know how can I make shared folders be faster than 5 seconds? I'd like to avoid rsync based solutions.

cherouvim
  • 30,497
  • 14
  • 99
  • 144
  • Is your vagrant box built with a different minor version of VirtualBox guest additions? I've had issues between minor versions between 5.0 vs 5.1, host vs. guest. – DanCat Mar 27 '17 at 01:43
  • See also tips: https://blog.theodo.com/2017/07/speed-vagrant-synced-folders/ – lubosdz Jun 24 '19 at 14:45

2 Answers2

3

Vagrant file sharing is slow if you have thousands of files and vagrant mounts home directory by default so try disabling the default share:

config.vm.synced_folder ".", "/vagrant", disabled: true

You may try enabling FS Cache. I didn't see much difference enabled or not but left enabled anyway... Install cachefilesd in the guest and add fsc to the mount options:

config.vm.synced_folder "src/", "/mnt/project", type: "nfs", 
                        mount_options: ['rw', 'vers=3', 'tcp', 'fsc']

And you'll probably have permission issues with NFS, you can use bindfs plugin for that:

config.bindfs.bind_folder "/mnt/project", "/var/www/drupal", 
                          owner: "www-data", group: "www-data"

Here's the final Vagrantfile we use for drupal8 development:

["vagrant-bindfs", "vagrant-vbguest"].each do |plugin|
    unless Vagrant.has_plugin?(plugin)
      raise plugin + ' plugin is not installed. Hint: vagrant plugin install ' + plugin
    end
end

Vagrant.configure("2") do |config|
  config.vm.box = "geerlingguy/ubuntu1604"

  # Shared folders
  config.vm.synced_folder ".", "/vagrant", disabled: true 
  config.vm.synced_folder "src/", "/mnt/drupal", type: "nfs", 
                          mount_options: ['rw', 'vers=3', 'tcp', 'fsc']
  config.bindfs.bind_folder "/mnt/drupal", "/opt/drupal", 
                            owner: "www-data", group: "www-data"

  config.vm.network "private_network", ip: "192.168.33.20"
  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end
end
madpoet
  • 872
  • 9
  • 26
0

you can mount a root folder "without sync" and mount other folders "with sync", this is my configuration for laravel and homestead :

folders:
  - map: "./"
    to: "/home/vagrant/green-rush"
    type: "nfs"
    options:
      disabled: true
  - map: "./app"
    to: "/home/vagrant/green-rush/app"
    type: "nfs"
  - map: "./resources"
    to: "/home/vagrant/green-rush/resources"
    type: "nfs"
  - map: "./routes"
    to: "/home/vagrant/green-rush/routes"
    type: "nfs"
  - map: "./tests"
    to: "/home/vagrant/green-rush/tests"
    type: "nfs"
  - map: "./public"
    to: "/home/vagrant/green-rush/public"
    type: "nfs"

now speed should be very close to 0.5 seconds in your case. You can mount all folders that you want as "synced folder" just don't mount a ".git folder"., because the most problematic folder is ".git" folder. Also good candidate for non mounting folder is "node_modules" folder. The only problem is that now files in root files are now not in sync but that is a compromise, you can manually move these files to vagrant with this command e.g. :

scp "C:\projects\test\.env" "vagrant@vagrant.local:/home/vagrant/test/.env"

or you can create a script that will do that for you automatically when any file is changed.

fico7489
  • 6,416
  • 5
  • 44
  • 77