gethostbyname_ex(hostname) extremely slow

自古美人都是妖i 提交于 2019-11-28 10:56:54

问题


At startup, IPython (qtconsole) calls socket.gethostbyname_ex(socket.gethostname())[2] to find a list of IP addresses that point to the machine. On a Linux server that I manage this call is extremely slow (>20s)... which I have trouble understanding as ip addr show seems to give the same information nearly instantaneously. Is there anything I can do to make this faster? Can this be a network configuration issue (I am behind a router)?

This issue is independent of IPython:

$ time python -c 'import socket; print(socket.gethostbyname_ex(socket.gethostname())[2])' 
['192.168.0.102']
python -c   0.07s user 0.02s system 0% cpu 28.190 total

Thanks.


回答1:


I had a similar problem. It happened that my hostname was localhost.localdomain, being lazy when installing the OS.

The solution was to give it a sane name by sudo vi /etc/hostname and changing it to myname.mydomain and now it runs in 1s.



来源:https://stackoverflow.com/questions/18544514/gethostbyname-exhostname-extremely-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!