Why is my gcloud command suddenly very slow inside WSL2
Asked Answered
C

4

15

When I run a simple command, it takes about 10 seconds to complete,

λ time gcloud version
Google Cloud SDK 293.0.0
beta 2019.05.17
bq 2.0.57
core 2020.05.15
gsutil 4.50

real    0m9.731s
user    0m0.735s
sys     0m1.690s

λ uname -a
Linux LAPTOP-U7E4CROH 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

λ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

I should note that I do not experience this slow behavior on the same laptop but within a git-bash environment - I only see this within WSL2 / Ubuntu.

I have tried to google around and I have found these two questions on SO, but they are not helping me:

Any ideas on how I can solve this?

Chamfron answered 22/5, 2020 at 10:37 Comment(2)
Can you edit your question and add the result of running traceroute www.googleapis.com or any other networking tool that can analyze the latency at each hop until the packets reach www.googleapis.com (by removing any sensitive information regarding your machine's IP)? Is the slowness experienced with all the commands, or some commands in general? Do you also have the Google Cloud SDK 293.0.0 version installed on the Windows Machine?Ealing
Also, do you get the same latency issue if you update to the latest release 294.0.0?Ealing
A
22

I have the same issue and it turns out that in WSL 2 when I run gcloud it actually turn to use the gcloud installed on my Windows system. Somehow it is very slow if you run the Windows gcloud from WSL 2, which is also never my intention.

I just disable appending Windows PATH to my WSL PATH all together after this. But you know the root cause.

For the sake of completeness, to disable this feature, edit the /etc/wsl.conf to add the following section:

[interop]
appendWindowsPath = false

and terminate the WSL distro (wsl.exe --terminate <distro_name>) to make it immediately effective.

Adey answered 20/7, 2020 at 13:55 Comment(4)
If the /etc/wsl.conf file is not there, you may add it. (According to 03/26/2021 learn.microsoft.com/en-us/windows/wsl/wsl-config)Lambkin
wsl.exe --list --running to get the current distro_name. This solution will break any WSL apps or scripts that do rely on the windows path. This did not fix slowness for me.Organelle
If which gcloud in wsl shell reports it is in a location like 'AppData/Local', it is picking up the windows version. Remove that from your path, and which cloud will either reveal the local linux gcloud or show that it is not installed. This worked for me.Organelle
I think the reason is that windows drive mounted in WSL is very slow... it always has been. Mount a drive from WSL to windows, access it with right click on file, takes about 10 seconds to show the dropdown. If you run a NPM project like this, god help you, lol. It's always been like this, gcloud is just another symptom I suspect.Administrator
F
6

I had the same issue, resolved it by reinstalling the SDK: https://cloud.google.com/sdk/docs/downloads-interactive#linux

You must reinstall using 'Interactive installation', which replaces the previous installation and updates the PATH.

'Non-interactive (silent) deployment' does not seem to improve the issue.

Hope this helps.

Ferreous answered 6/7, 2020 at 14:27 Comment(1)
in the meantime I had a re-install of my system and this particular problem went away, so maybe a reinstall is indeed worth trying if someone else is running into this problem.Chamfron
P
1

I had the same issue and the only solution that worked for me was to set an alias for the gcloud command such that it gets executed by cmd.exe like so:

# in ~/.bashrc

alias gcloud="cmd.exe /c gcloud"

Then simply restart your terminal or run $ source ~/.bashrc, and the alias will take effect.

Of course, this assumes you have the gcloud CLI installed and added to your windows PATH.

Plenteous answered 17/6, 2022 at 0:53 Comment(0)
C
0

As @kylechun9 said WSL 2 when you run gcloud it uses the gcloud installed on my Windows system, so to avoid it just install it on your WSL2 distro

Coastal answered 7/6, 2023 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.