Rails Windows Vagrant very slow response time

2019-04-10 01:24发布

问题:

I'm running:

 - Vagrant 1.7.1
 - Rails 4.1.4
 - Thin 1.6.1
 - Windows 7

Every static file takes more than a second to be sent. A page can take around 20 seconds to load on my PC, while on the colleague's Linux machine it takes an instant. There were some posts that say webrick's reverse DNS lookup was the problem, but nobody is saying that Thin suffers from the same problem.

Vagrant file:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "custom_box"
  config.vm.network :forwarded_port, guest: 3000, host: 3000
end

回答1:

After trying a few things, nothing worked. I couldn't make nfs work on windows. Then I found about rsync! It solved the performance issue perfectly. See more about rsync and vagrant here: http://docs.vagrantup.com/v2/synced-folders/rsync.html

On windows, use it with mingw, it works right away: http://www.mingw.org/



回答2:

Synced folder performance on Windows is abysmal with Virtualbox (which is the default). I'd suggest installing WinNFSd plugin for Vagrant and then adding these two lines to your Vagrantfile:

config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder ".", "/vagrant", type: "nfs" 

That will add NFS support on Windows which has some kinks but still 10x better than the default.



回答3:

Assign hostname and private IP to it.

$ cat Vagrantfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "custom_box"
     config.vm.host_name = "rails.example.com"
     config.vm.network :private_network, ip: "192.168.1.1"
     config.vm.network :forwarded_port, guest: 3000, host: 3000
  end   
end

After updated the Vagrantfile, start it with:

vagrant up
vagrant ssh

Then access the website http://192.168.1.1:3000 from your own computer, should be faster now.



回答4:

File system is the problem. I've managed to "install" nfs on windows 10 with Winnfsd, by following those instructions:

https://github.com/dziad/WinNFSdBinary/wiki

After installation WinNFSd refused to run - msvcr120d.dll library was missing so I followed this tutorial:

https://www.youtube.com/watch?v=H8WuKaHslvA

And it finally runs! Much faster than before, but again, not as fast I expected (running it on samsung evo ssd), but it's usable.



回答5:

Now I'm running windows 10 and decided to try Linux Subsystem on Windows. It works great, this is by far the best solution for developing Rails apps on Windows.