Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Cygwin execute shell commands very slowly?

Tags:

bash

cygwin

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 anybody know why?

It's a fresh install of cygwin 1.7 on win7.

thanks to Jared's testing idea, I modified the command to this(adds bash -c):

time for i in {1..10} ; do bash -c "echo Hello" ; done
Hello
...
real 0m7.711s //it's the problem
user 0m0.091s
sys 0m0.476s
like image 367
Lcsky Avatar asked Jul 25 '11 03:07

Lcsky


People also ask

How can I make Cygwin faster?

Trim down your Windows PATH (to the bare bones like %SystemRoot%\system32;%SystemRoot%) Remove things you don't need from bashrc and bash_profile. Move things you only need in your terminal window from bashrc to bash_profile. One surprisingly large time suck in Cygwin is Bash completion.

Is Cygwin slow?

Due to limitations of Windows and the NT kernel, Cygwin is often a lot slower than Linux when running, and one particular slowdown is due to the complex way Cygwin has to emulate the Linux fork() call.

What Shell does Cygwin use?

Cygwin brings Linux to the Windows environment. Users can interact with Cygwin through a Unix shell, such as bash, tcsh or zsh. From there, they can issue Unix commands much like they would on a Unix or Linux computer.


4 Answers

How about excluding Cygwin paths from your antivirus software ?

like image 178
dotz Avatar answered Nov 02 '22 22:11

dotz


Check your path. Referring a non-existant path or a very slow network share can cause the symptoms you are describing.

like image 43
Jeremy J Starcher Avatar answered Nov 02 '22 22:11

Jeremy J Starcher


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.
like image 31
metatechbe Avatar answered Nov 02 '22 22:11

metatechbe


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!

like image 24
Lcsky Avatar answered Nov 02 '22 20:11

Lcsky