gpt4 book ai didi

gcloud - 为什么 gcloud 命令启动缓慢?

转载 作者:行者123 更新时间:2023-12-04 23:40:10 26 4
gpt4 key购买 nike

只需输入 gcloud寻求帮助需要 5 秒。

$ gcloud
...
gcloud 0.30s user 0.13s system 7% cpu 5.508 total

$ gcloud version
Google Cloud SDK 128.0.0
alpha 2016.01.12
bq 2.0.24
bq-nix 2.0.24
core 2016.09.23
core-nix 2016.09.20
gcloud
gsutil 4.21
gsutil-nix 4.21
kubectl
kubectl-darwin-x86_64 1.3.7

$ uname -a
Darwin hiroshi-MacBook.local 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64

最佳答案

编辑 2017-03-31:Zachary 说 gcloud 148.0.0 解决了这个问题。所以试试 gcloud components update .见 https://stackoverflow.com/users/4922212/zachary-newman

tl;博士

原来socket.gethostbyaddr(socket.gethostname()) .local 很慢macOS 中的主机名。

$ python -i
>>> socket.gethostname()
'hiroshi-MacBook.local'
>>> socket.gethostbyaddr(socket.gethostname()) # it takes about 5 seconds
('localhost', ['1.0.0.127.in-addr.arpa'], ['127.0.0.1'])

因此,作为解决方法,只需将主机名添加到/etc/hosts 的 localhost 行。
127.0.0.1     localhost hiroshi-Macbook.local                             

之后是返回值不同,但都是瞬间返回。
>>> socket.gethostbyaddr(socket.gethostname())
('localhost', ['1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'], ['::1'])

我如何到达那里

gcloud 命令在哪里:
$ which gcloud
/Users/hiroshi/google-cloud-sdk/bin/gcloud

编辑shell脚本的结束行...
...
+ echo "$CLOUDSDK_PYTHON" $CLOUDSDK_PYTHON_ARGS "${CLOUDSDK_ROOT_DIR}/lib/gcloud.py" "$@"
"$CLOUDSDK_PYTHON" $CLOUDSDK_PYTHON_ARGS "${CLOUDSDK_ROOT_DIR}/lib/gcloud.py" "$@"

回显 gcloud.py 所在的位置:
$ gcloud
python2.7 -S /Users/hiroshi/google-cloud-sdk/lib/gcloud.py

好的。谁花这5秒?
$ python2.7 -S -m cProfile -s time /Users/hiroshi/google-cloud-sdk/lib/gcloud.py
173315 function calls (168167 primitive calls) in 5.451 seconds

Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno(function)
1 5.062 5.062 5.062 5.062 {_socket.gethostbyaddr}
...
_socket.gethostbyaddr是。

函数调用和回溯的参数是什么样的?
我在 gcloud.py 的 main() 之前添加了一些行
import traceback
def mygethostbyaddr(addr):
print addr
traceback.print_stack()
return addr
import socket
socket.gethostbyaddr = mygethostbyaddr

再次执行 gcloud。
我知道这是我机器的 .local 名称。
$ gcloud
hiroshi-MacBook.local
File "/Users/hiroshi/google-cloud-sdk/lib/gcloud.py", line 74, in <module>
main()
File "/Users/hiroshi/google-cloud-sdk/lib/gcloud.py", line 70, in main
sys.exit(googlecloudsdk.gcloud_main.main())
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/gcloud_main.py", line 121, in main
metrics.Started(START_TIME)
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 411, in Wrapper
return func(*args, **kwds)
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 554, in Started
collector = _MetricsCollector.GetCollector()
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 139, in GetCollector
_MetricsCollector._instance = _MetricsCollector()
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 197, in __init__
hostname = socket.getfqdn()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 141, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
File "/Users/hiroshi/google-cloud-sdk/lib/gcloud.py", line 32, in mygethostbyaddr
traceback.print_stack()

关于gcloud - 为什么 gcloud 命令启动缓慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39864910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com