Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my gcloud command suddenly very slow inside WSL2

Tags:

gcloud

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:

  • google compute engine tool gcloud is exceptionally slow
  • Why gcloud command is slow to start?

Any ideas on how I can solve this?

like image 576
Frederik Avatar asked May 22 '20 10:05

Frederik


People also ask

Why is gcloud so slow?

Network (yours and/or cloud provider's) – Backhauling network traffic to a central data center for security and data protection can also impact performance, especially in cloud-based and mobile applications. More data-intensive applications such as video and rich media can also slow the network.

Where do I run gcloud commands?

Running gcloud CLI commands You can run gcloud CLI commands from the command line and from scripts and other automations—for example, when using Jenkins to automate Google Cloud tasks. Note: gcloud CLI reference documentation and examples use backslashes, \ , to denote long commands.

What does gcloud init do?

gcloud init sets the project property in the configuration to the property you choose. If you have access to more than 200 projects, you will be prompted to enter a project id, create a new project, or list projects. This account has a lot of projects! Listing them all can take a while.


2 Answers

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.

like image 114
kylechun9 Avatar answered Jan 04 '23 15:01

kylechun9


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.

like image 33
Akshay Narayan Avatar answered Jan 04 '23 16:01

Akshay Narayan