Why does Cygwin execute shell commands very slowly?

前端 未结 11 1133
说谎
说谎 2020-12-08 11:29

Just tests a very simple command like:

while true; do bash -c \"echo hello\"; done

You will find how much slow the bash in Cygwin is. Does

相关标签:
11条回答
  • 2020-12-08 11:52

    Below are 3 possible causes which I encountered. Of course, other problems not mentioned can also cause slow shell commands in Cygwin.

    • If you have the option "Automatically detect settings" in "LAN Settings", Windows will use the WPAD protocol to discover the local HTTP proxy. First it will send a DHCP "Inform" request with option 252, then it will try a DNS lookup on "wpad". These 2 operations can take a few seconds to time-out.

    • If the shell accesses some paths like /cygdrive/... , a NetBIOS name query will be executed, which can also take some time to time out.

    • If the shell accesses some paths like //mypath/... , a NetBIOS name query will be executed, which can also take some time to time out.

    Solutions :

    • Disable "Automatically detect settings" in "LAN Settings" in the Windows "Internet Options" control panel.

    • Add the following entry in %SystemRoot%\system32\drivers\etc\hosts :

    127.0.0.1 localhost cygdrive wpad

    • Make sure to avoid double slashes at the beginning of all paths.
    0 讨论(0)
  • 2020-12-08 11:53

    How about excluding Cygwin paths from your antivirus software ?

    0 讨论(0)
  • 2020-12-08 11:54

    This is how this problem manifested for me. For the first say 20 commands entered at the cygwin prompt it is fast, then it abruptly becomes painfully slow.

    I checked that every item in my path was a valid directory.

    I tried an authentication fix suggested elsewhere - https://superuser.com/questions/877051/cygwin-from-windows-very-slow-laggy/1247517 . It didn't work for me.

    I replaced my exisitng virus scanner (System Center Endpoint Protection) with Sophos. That fixed the problem for me. Hope this helps.

    0 讨论(0)
  • 2020-12-08 11:57

    On Comodo Internet Security Premium 10, i added "C:\Users\\Documents\MobaXterm\slash\bin" to the list of trusted files. (Settings -> File rating -> File list). Local terminal is fast again now.

    0 讨论(0)
  • 2020-12-08 11:59

    Finally, I found the source - a service named "QQPCMgr RTP Service" running on my office computer, it's the real time protection service of "QQ PC Manager".

    By disabling it, the time of the script in the question falls back to:

    real    0m0.943s
    user    0m0.105s
    sys     0m0.231s
    

    I have told the developers of QQPCMgr about this, hope they will find the reason.

    This still much slower than Linux, but gets the same "real time" of other cygwin computers.

    Thank you all!

    0 讨论(0)
  • 2020-12-08 11:59

    Let's put some numbers to it. I ran the following:

    time for i in {1..1000} ; do echo "Hello" ; done
    

    The result I get from a standard Cygwin bash window is:

    ...
    Hello
    Hello
    
    real    0m0.584s
    user    0m0.031s
    sys     0m0.000s
    

    And from a xterm bash window on the same system I get:

    ...
    Hello
    Hello
    
    real    0m0.037s
    user    0m0.016s
    sys     0m0.000s
    

    I think this pretty much answers the question for you. The problem is you're going through a "Windows" "cmd" like window, which is inherently slow. Cygwin itself isn't the problem, it's the display trying to keep up that is slowing things down (for this test).

    0 讨论(0)
提交回复
热议问题