vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

Vagrant CLI on Windows is very slow

Open keilma opened this issue 4 years ago • 76 comments

Hello,

I was not able to find something useful to solve this issue so I will try it here. I've a fresh installation of Vagrant (no plugins) on my host, but the response of the CLI is very very slow. For example it takes 19 seconds to get the output of "vagrant version":

PS > Measure-Command { vagrant version }

Days : 0 Hours : 0 Minutes : 0 Seconds : 19 Milliseconds : 460 Ticks : 194606842 TotalDays : 0,000225239400462963 TotalHours : 0,00540574561111111 TotalMinutes : 0,324344736666667 TotalSeconds : 19,4606842 TotalMilliseconds : 19460,6842

Environment: Windows 10 2004 Build 19041.450 (32 GB RAM, Core i7), Vagrant 2.2.10, VirtualBox 6.1.12.

Thanks in advance.

Kind regards Marcel

keilma avatar Aug 26 '20 18:08 keilma

Same here; running vagrant version takes about 7 seconds.

Environment: Windows 10 1909 (18363.1139), 16GB RAM, Core i7, Vagrant 2.2.10, VirtualBox 6.1.8.

PS> measure-command { vagrant version }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 7
Milliseconds      : 423
Ticks             : 74233471
TotalDays         : 8.5918369212963E-05
TotalHours        : 0.00206204086111111
TotalMinutes      : 0.123722451666667
TotalSeconds      : 7.4233471
TotalMilliseconds : 7423.3471

Tried adding C:\HashiCorp to the virus scan exclusion list, but no difference.

yasny avatar Oct 29 '20 08:10 yasny

This may be due to powershell compiling assemblies on startup which is causing the delay. Precompiling them can resolve the issue if it is indeed the root cause: https://serverfault.com/questions/761301/calling-powershell-exe-is-extremely-slow/761473#761473

chrisroberts avatar Oct 30 '20 17:10 chrisroberts

@chrisroberts Thanks for the tip, but Vagrant is also slow using normal cmd.exe.

C:\>cmd /v:on /c "echo !TIME! & vagrant version & echo !TIME!"
 7:38:16.06
Installed Version: 2.2.10
Latest Version: 2.2.10

You're running an up-to-date version of Vagrant!
 7:38:22.76

Not as accurate as measure-command, but it's taking about 7 seconds.

I'm thinking it's a problem running the embedded ruby environment on Windows that's slow...

yasny avatar Nov 01 '20 22:11 yasny

Using cmd it takes 19 seconds on my notebook:

cmd /v:on /c "echo !TIME! & vagrant version & echo !TIME!"
10:42:59,13
Installed Version: 2.2.10
Latest Version: 2.2.10

You're running an up-to-date version of Vagrant!
10:43:18,49

keilma avatar Nov 02 '20 09:11 keilma

@yasny / @keilma It is not an issue with running Vagrant under powershell or cmd. Vagrant executes powershell commands on Windows to determine things like available providers and user permissions. If powershell itself is slow to start, then it will result in Vagrant being slow as well. This is where precompiling the assemblies can help.

chrisroberts avatar Nov 03 '20 21:11 chrisroberts

Hi @chrisroberts,

normal powershell operations or other scripts are working normal on my system. In the thread on serverfault it takes ~7 seconds for a write-host, on my host it's done in miliseconds:

PS> measure-command { pwsh "Write-Host test" }

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 330
Ticks             : 3302527
TotalDays         : 3,82236921296296E-06
TotalHours        : 9,17368611111111E-05
TotalMinutes      : 0,00550421166666667
TotalSeconds      : 0,3302527
TotalMilliseconds : 330,2527

keilma avatar Nov 05 '20 07:11 keilma

@chrisroberts Thanks for your input. Do you have any other suggestions? It's really difficult to work with Vagrant on Windows :(

AMoghrabi avatar Nov 23 '20 22:11 AMoghrabi

Difficult? Not usable here.

keilma avatar Nov 24 '20 08:11 keilma

I got 28 sec for "vagarant version". When I run full script (provision docker-compose + run docker-compose.yml) docker it takes ~40minutes. After that "vagrant ssh" takes a very long time to connect. Wonder how you guys use it on Windows.

Edit: that information above is for my work machine. For my much less powerful home PC, it's approximately 3 times faster. Maybe there is some big-brother s/w in between

lispercat avatar Dec 29 '20 03:12 lispercat

I see people in this bug report performing measurements on vagrant version, but that won't be accurate at all because it performs an HTTP request to Vagrant to fetch the latest version, so you'll have a variable extra delay from that request. Personally, I test vagrant help instead.

I did find out that it's (for some reason) faster if Vagrant is running elevated (with administrator permissions): image

There also doesn't seem to be any difference between running in Windows 10's pre-installed PowerShell or PowerShell 7, because it will ALWAYS call out to C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.

Testing the command inside of a Vagrant environment (in this case Laravel Homestead) seems to make it run even faster: image

Pyker avatar Dec 29 '20 11:12 Pyker

I also find the slow vagrant cli quit annoying, especially vagrant help. I normally get about 2.3s with the measure-command. Every time I use vagrant, I lose focus as it takes so long to complete any command that I switch tasks and get distracted.

I used SysInternals Process Monitor to record the events, filtering on vagrant.exe, ruby.exe, and powershell.exe.

vagrant_help_slow_2021-01-03_180016

It shows that majority of the execution time is the ruby process. I think the root cause is that Ruby, at least on Windows, is very slow. The PowerShell processes take a lot less time than ruby. The vagrant.exe wrapper takes very small time.

berney avatar Jan 03 '21 07:01 berney

Please remove the needs-repo and waiting-reply labels as clear repo steps have been provided and powershell has been eliminated.

berney avatar Jan 11 '21 00:01 berney

We experience same delay problems. We have stopped using any vagrant commands which have alternatives on windows. I.E. vagrant ssh we use ssh directly on windows to connect to VM. The biggest issue for us is rsync. We need to send files often from Windows Vagrant Host to VM. Running vagrant rsync almost every 5 minutes drives us crazy.

skalinkin avatar Jan 16 '21 03:01 skalinkin

We experience same delay problems. We have stopped using any vagrant commands which have alternatives on windows. I.E. vagrant ssh we use ssh directly on windows to connect to VM. The biggest issue for us is rsync. We need to send files often from Windows Vagrant Host to VM. Running vagrant rsync almost every 5 minutes drives us crazy.

@skalinkin Just use rsync directly. Its a binary packaged in vagrant. Or you can get cwRsync, msys2 rsync etc.

berney avatar Jan 16 '21 03:01 berney

I've just experienced this and found a solution here: https://www.gitmemory.com/issue/hashicorp/vagrant/10521/492835941 Commenting out those functions and just returning false sped up my cli (e.g. vagrant --help) by 4x - i.e. went from 8-9 seconds down to 2

I'm not 100% certain what these functions are required for, but as two of them are for Hyper-V which I'm not using on this machine I'm assuming it should be fairly safe to disable them

C:\HashiCorp\Vagrant\embedded\gems\2.2.14\gems\vagrant-2.2.14\lib\vagrant\util\platform.rb
  def windows_admin?
    return false

  def windows_hyperv_admin?
    return false

  def windows_hyperv_enabled?
    return false

vuzzlevuzz avatar Feb 11 '21 22:02 vuzzlevuzz

I've just experienced this and found a solution here: https://www.gitmemory.com/issue/hashicorp/vagrant/10521/492835941 Commenting out those functions and just returning false sped up my cli (e.g. vagrant --help) by 4x - i.e. went from 8-9 seconds down to 2

2 seconds to display help is still 2s too long.

berney avatar Feb 12 '21 00:02 berney

cmd /v:on /c "echo !TIME! & vagrant help > nul & echo !TIME!" 17:30:46.36 17:33:42.58

That's ridiculous, unusable...

I can't disable powershell/hyperv etc. as I'm using them (hyper-v).

SecDWizar avatar Feb 28 '21 15:02 SecDWizar

I applied @vuzzlevuzz's patch but it still takes over 10 seconds to "vagrant ssh" to a ubuntu vm from CMD (not PowerShell). Running version 2.2.14 on latest Windows 10 with latest VirtualBox.

jarlva avatar Mar 05 '21 06:03 jarlva

Not just on Windows

$ uname -a
Linux mb-spectre 5.8.0-45-generic #51~20.04.1-Ubuntu SMP Tue Feb 23 13:46:31 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ vagrant --version
Vagrant 2.2.15
$ time vagrant --help | head -n 4
Usage: vagrant [options] <command> [<args>]

    -h, --help                       Print this help.

real	0m8.321s
user	0m3.132s
sys	0m1.211s

mbarkhau avatar Apr 15 '21 20:04 mbarkhau

With config.vm.boot_timeout = 7200 'vagrant up' has been failed by timeout. Is there any way to speed up vagrant?

Raxta avatar May 19 '21 13:05 Raxta

After nearly one year there is still no remedy in sight?

PS> Measure-Command { vg -h }

Days : 0 Hours : 0 Minutes : 0 Seconds : 5 Milliseconds : 270 Ticks : 52704992 TotalDays : 6.10011481481481E-05 TotalHours : 0.00146402755555556 TotalMinutes : 0.0878416533333333 TotalSeconds : 5.2704992 TotalMilliseconds : 5270.4992

PS> vg -v Vagrant 2.2.16

NgrNxk avatar May 26 '21 18:05 NgrNxk

While it is convenient (and portable way) to use PowerShell to source Windows host info it is a poor choice.

Most of that info could be extracted by reading registry / invoking other utilities.

I was surprised when my report was closed https://github.com/hashicorp/vagrant/issues/10521

Basically Vagrant is not usable on Windows. Small number of voices means the product is no longer popular on Windows.

gavenkoa avatar Jun 02 '21 11:06 gavenkoa

@chrisroberts Could you please remove the needs-repo and waiting-reply labels, repo steps are measure-command { vagrant help } in powershell.

Powershell was eliminated in https://github.com/hashicorp/vagrant/issues/11853#issuecomment-753578352

berney avatar Jun 07 '21 05:06 berney

Any news on that matter? I've just updated to Windows 20H2 (19042.630) and experience the same slowness.

vagrant -v
Vagrant 2.2.16

Measure-Command { vagrant help }


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 11
Milliseconds      : 920
Ticks             : 119209993
TotalDays         : 0,000137974528935185
TotalHours        : 0,00331138869444444
TotalMinutes      : 0,198683321666667
TotalSeconds      : 11,9209993
TotalMilliseconds : 11920,9993

and it's the same in WSL2 (Ubuntu 20.04 LTS) :

$ vagrant -v
Vagrant 2.2.16

$ time vagrant help
(...)
real    0m14.309s
user    0m0.578s
sys     0m1.359s

rbuquet avatar Jul 07 '21 16:07 rbuquet

and it's the same in WSL2 (Ubuntu 20.04 LTS) :

Probably you configured passing control from WSL2 to Windows? WSL's vagrant delegates all commands to native Windows vagrant utility. If it is slow in Windows it is slow in WSL )) If it is not the case they just know about WSL env and try to reuse Windows powershell from Linux...

For that reason I gave up using Vagrant in WSL 1 (and patched Windows Vagrant commending some stupidly slow Hyper-virt checks, I'm with VBox xD).

gavenkoa avatar Jul 08 '21 06:07 gavenkoa

Please use VAGRANT_LOG for testing. They log relevant information:

VAGRANT_LOG=debug vagrant status

In addition install ts utility for timestamps (to find bottlenecks easier):

VAGRANT_LOG=info vagrant halt 2>&1 | ts -i %.S

gavenkoa avatar Jul 08 '21 06:07 gavenkoa

Actually there is a difference between Windows and WSL. Sorry I forgot to set the env variable VAGRANT_CHECKPOINT_DISABLE in WSL. Here are new measures:

Windows 20H2 (19042.630) through Git Bash (from Git For Windows)

$ vagrant -v
Vagrant 2.2.16

$ env | grep VAGRANT
VAGRANT_CHECKPOINT_DISABLE=true

$ time vagrant help
(...)
real    0m9.062s
user    0m0.031s
sys     0m0.062s

WSL2 (Ubuntu 20.04 LTS) on the same Windows but this time with VAGRANT_CHECKPOINT_DISABLE

$ vagrant -v
Vagrant 2.2.16

$ env | grep VAGRANT
VAGRANT_CHECKPOINT_DISABLE=true
VAGRANT_WSL_ENABLE_WINDOWS_ACCESS=1

$ time vagrant help
(...)
real    0m3.905s
user    0m0.859s
sys     0m1.031s

rbuquet avatar Jul 08 '21 09:07 rbuquet

vagrant help isn't useful for testing. You don't use this command normally. Try vagrant status instead. vagrant help is meaningless.

gavenkoa avatar Jul 08 '21 09:07 gavenkoa

Any update on this?

oleggtro avatar Aug 12 '21 08:08 oleggtro

I found a solution that helped me, I updated my bios and in the power settings I set max performance

Try also turn off windows defender, it iincrease vagrant performance a lot

adrianmachal avatar Aug 20 '21 15:08 adrianmachal

I found a solution that helped me, I updated my bios and in the power settings I set max performance

No offense but it sounds as a tip from Windows forums ))

Try also turn off windows defender, it iincrease vagrant performance a lot

Definitely that helps, Vagrant relies on Ruby which loads lots of files. Each file is scanned by antivirus,

Instead of disabling Defender entirely you can exclude installation, configuration & VMs folders from active monitoring.

gavenkoa avatar Aug 21 '21 16:08 gavenkoa

Maybe it could be useful ? (Windows 10 + Hyper-V)

ghusta avatar Sep 16 '21 19:09 ghusta

Maybe it could be useful ? (Windows 10 + Hyper-V)

No, vagrant CLI invoke powershell several times. PowerShell is known to be slow a a hell (bootrapping).

gavenkoa avatar Sep 19 '21 12:09 gavenkoa

@gavenkoa root cause is Ruby not powershell. See https://github.com/hashicorp/vagrant/issues/11853#issuecomment-753578352.

berney avatar Oct 12 '21 17:10 berney

@berney For vagrant help it is Ruby. But we don't normally use vagrant help. If you profile vagrant up startup time jumps from 2s to 15s because of PowerShell. I can tolerate 2 sec but not 15s.

gavenkoa avatar Oct 13 '21 09:10 gavenkoa

I think 2s to print some text is too slow. I can switch to a browser and google an answer before the command prints it out on the console. The most basic things are very slow, and everything else too slow as well. The powershell execution times I measured are negligible vs ruby. I can wait 15s to do something complicated like starting a VM if other tools are comparable speeds.

It is annoying to forget the syntax and wanting to quickly check it and having it so slow, before you can complete your mental task and move on. Using vagrant CLI to do anything is too slow to be usable from a UX point of view. Very first thing I do is setup sshconfig so I can use native ssh command and avoid vagrant. The less you need to use vagrant command the happier you'll be IMO.

The issue is on Linux as well https://github.com/hashicorp/vagrant/issues/11853#issuecomment-820705594. I'm doubting PowerShell would be used there.

Regardless of whether its ruby or powershell, vagrant needs to be much more performant to have an enjoyable UX.

berney avatar Oct 13 '21 13:10 berney

This is still an issue (14s for vagrant status): Measure-Command { vagrant status } Days : 0 Hours : 0 Minutes : 0 Seconds : 14 Milliseconds : 221 Ticks : 142219676 TotalDays : 0.000164606106481481 TotalHours : 0.00395054655555556 TotalMinutes : 0.237032793333333 TotalSeconds : 14.2219676 TotalMilliseconds : 14221.9676

I even entered a wrong command: vagrant sttus and it took 15s.

dvader avatar Oct 13 '21 19:10 dvader

also very slow here(windows 10, with Windows Terminal)

drriguz avatar Oct 27 '21 07:10 drriguz

are you guys planning to fix this issue? it's painful to wait about 1 minute just to boot my dev environment (homestead hyper-v)

ezralazuardy avatar Nov 26 '21 19:11 ezralazuardy

Homestead Hyper-V for some reason has a 30 second delay on boot with GRUB. That's why it takes forever for vagrant up to get an IP from the machine.

Pyker avatar Nov 27 '21 00:11 Pyker

Maybe it could be useful ? (Windows 10 + Hyper-V)

Yes! After making changes to my vagrantfile the time to vagrant up has been improved significantly, as well as the actual performance of the VM as well:

config.vm.provider "hyperv" do |h|       
    h.enable_virtualization_extensions = true
    h.linked_clone = true
end

config.vm.provider "virtualbox" do |vb|
    vb.customize [
        "modifyvm", :id,
	"--memory", "4096",
	"--cpus", "2"
    ]
end

Vagrant: 2.2.18 VirtualBox: 6.1.30 This was with a regular "vagrant up" ( not specifying --provider )

Pat-Relentless avatar Dec 10 '21 19:12 Pat-Relentless

On the latest release as of today, vagrant is still so slow that vagrant ssh times out. Is there any effort being made to fix this? It's practically unusable.

garlic-os avatar Jul 19 '22 03:07 garlic-os

Vagrant took about 10 seconds just to get the status of a Hyper-V virtual machine. Yikes!

  • Ryzen 9 5900X
  • 32GB DDR4
  • 1 TB Samsung NVMe SSD
  • Windows 11 Developer Preview

image

Meanwhile, the Get-VM command in PowerShell takes a mere 21 milliseconds to execute. ⏱️

image

Definitely seems like Vagrant has some kind of performance issues.

pcgeek86 avatar Sep 02 '22 13:09 pcgeek86

Vagrant is pretty much unusable in this state… Is there anyone looking into this?

oleggtro avatar Sep 03 '22 14:09 oleggtro

For those who suffer I work with patched Vagrant for 3 years, file platform.rb.diff:

c:/opt/Vagrant/embedded/gems/2.2.3/gems/vagrant-2.2.3/lib/vagrant/util/platform.rb


--- platform.rb.orig	2020-09-29 14:01:55.477153300 +0300
+++ platform.rb	2019-05-16 00:42:37.032299600 +0300
@@ -75,6 +75,8 @@
         #
         # @return [Boolean]
         def windows_admin?
+          # EDITED gavenkoa
+          return false
           return @_windows_admin if defined?(@_windows_admin)
 
           @_windows_admin = -> {
@@ -99,6 +101,8 @@
         #
         # @return [Boolean]
         def windows_hyperv_admin?
+          # EDITED gavenkoa
+          return false
           return @_windows_hyperv_admin if defined?(@_windows_hyperv_admin)
 
           if ENV["VAGRANT_IS_HYPERV_ADMIN"]
@@ -136,6 +140,8 @@
         #
         # @return [Boolean]
         def windows_hyperv_enabled?
+          # EDITED gavenkoa
+          return false
           return @_windows_hyperv_enabled if defined?(@_windows_hyperv_enabled)
 
           @_windows_hyperv_enabled = -> {

Note that my provider is VirtualBox so I disabled calls to PowerShell that should return false about Hyper-V.

This reduces slowness from 15 sec to 2-4 sec. My corporate antivirus adds additional slowness so in your case it might run faster.

gavenkoa avatar Sep 03 '22 19:09 gavenkoa

Shaved of one second, thanks. From 9 to 8 seconds. Piss weak programming from Hashicorp IMO.

kaspars-vilde avatar Sep 09 '22 10:09 kaspars-vilde