35

Suddenly all Cygwin commands I start from the Windows command line have a ~10-20 second lag before they execute, so that Cygwin becomes totally unusable. I already tried to reinstall without success.

Executing the commands from within a Bash shell window, works fine (while starting Bash I see the lag). Removing all entries from my local PATH variable doesn't have an influence. I use Windows 7 x64 and Cygwin x64 v 1.7.34 (0.285/5/3).

3

7 Answers 7

27

Occasionally I work in a Windows domain with thousands of users.

I don't want to do any best-guess approach. I would prefer Cygwin to cache user information on an as-needed basis. It turns out this is easy to do.

Simply run cygserver on login.

To set this up properly, run cygserver-config once only. This will set up cygserver to run as a Windows service with the correct credentials. Do this from an administrator Cygwin window.

$ cygserver-config
Generating /etc/cygserver.conf file

Warning: The following function requires administrator privileges!

Do you want to install cygserver as service?
(Say "no" if it's already installed as service) (yes/no) yes

The service has been installed under LocalSystem account.
To start it, call `net start cygserver' or `cygrunsrv -S cygserver'.

Further configuration options are available by editing the configuration
file /etc/cygserver.conf. Please read the inline information in that
file carefully. The best option for the start is to just leave it alone.

Basic Cygserver configuration finished. Have fun!

What does cygserver do for me?

Have a look at the documentation over at the Cygwin site. Basically it does the user caching stuff, together with ensuring IPC works between all Cygwin processes.

Your mileage may vary of course, but this is now my preferred way of working. I should have done it years ago.

8
  • 1
    This is great! thanks for sharing after so long time.Using this file access through /cygdrive is also much faster now compared to before
    – 85fce
    Mar 1, 2017 at 9:36
  • /usr/bin/cygserver-config: line 181: cygrunsrv: command not found, C:/cygwin64/bin is on the PATH, running as administrator...
    – Troyseph
    Oct 16, 2017 at 10:31
  • 1
    @Troyseph Does C:\cygwin64\bin\cygrunsrv.exe exist? Have you erroneously used forward slashes (/) in your %PATH%? Is the cygrunsrv package installed?
    – bobbogo
    Oct 16, 2017 at 10:45
  • 2
    I just tried this, but I ran into a problem: after a reboot, Cygwin Terminal failed to run. The solution for that is explained here (summary: run services.msc and set cygserver to Automatic (Delayed Start)). Nov 28, 2019 at 1:12
  • 1
    I also wanted to note that the solution started to work for me only after system reboot. Feb 14, 2020 at 13:48
19

It seems to be to do with authentication. For me, 40 seconds to get something to execute. After that though, process creation in that process tree seems pretty quick.

https://www.cygwin.com/faq.html#faq.using.startup-slow

So, I

  • Made a cache of my local authentication, and my own Active Directory (AD) credentials

    $ mkpasswd -l -c >/etc/passwd
    $ mkgroup -l -c >/etc/group
    
  • Told Cygwin just to use these two files

    $ echo 'passwd: files' >/etc/nsswitch.conf
    $ echo 'group: files' >>/etc/nsswitch.conf
    

I killed all Cygwin processes and started again. Everything now runs nice and fast. I will remove this hack on every Cygwin DLL file update and see how I get on.

This is just a sketch—you will at least want to keep backups!

EDIT

Deprecated. See my more recent answer to this question for a better (IMHO) solution.

5
  • 2
    worked for me... and didn't have to install a service!
    – Droj
    Jun 16, 2017 at 16:33
  • @bobbogo Your answer is at the bottom for me. Which answer are you referring to in your edit at the end? Thanks!
    – jpaugh
    Mar 16, 2018 at 17:59
  • good to know about this, although it can't explain why "All cygwin commands ... have a ~10-20 second lag before they execute".
    – philwalk
    Mar 20, 2018 at 17:08
  • 1
    @philwalk I think it does. The problem is that at start-up Cygwin has to populate its user database. This takes a long time when you are inside a big windoze domain. Not every command suffers this delay, only the first in any process tree.
    – bobbogo
    Mar 21, 2018 at 11:28
  • 1
    Used a solution with cygserver first but it allowed to speedup a console starting time only and later e.g. trying to CD to a dir before clicking tab for a dir name completion it thought for a long time again and that solution doesn't help against this one which helped just great :) Thanks!
    – VirtualVAT
    Aug 26, 2021 at 12:11
2

As a footnote, I just found that I had to rebuild the passwd and group files after a Cygwin update. As the slow behaviour was happening again, the autorebase part of the install took several days to complete.

I also did not need to modify the default nsswitch.conf on my (Windows 10) system.

By the way, the slow behaviour also showed itself with the Windows command prompt and portable applications. Some portable applications took several hours to produce a window when started.

1
  • What do you mean rebuild them? Just make new, empty versions of them?
    – user13743
    Jun 17, 2019 at 23:51
2

Read the update below, this turned out not to be the issue.

I've been suffering from an extreme version of this problem, although it's intermittent. When the problem exists, all commands take between 20 seconds and in the most extreme cases several minutes. It will occur for several days, and then it will go away for several days. BTW, I have an extremely fast system with lots of DRAM, SSD drives, etc.

I now finally have a candidate theory that might explain things. I just updated Cygwin via setup-x86_64.exe (which I do infrequently) and afterwards things are extremely responsive again (literally 1000s of times faster than before). I'm guessing the rebaseall at the end of the update is what made the difference.

Update

The speedup I saw before was apparently a coincidence; when the problem reappeared a month later, this didn't fix it. It turns out that disabling Windows Defender live protection instantly resolved the slowdown.

1
  • 3
    disabling Windows Defender live protection instantly resolved the slowdown - known issue
    – gavenkoa
    Jan 7, 2019 at 22:47
1

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

I tried the above authentication fix. It didn't work for me.

The Cygwin FAQ reports that Cygwin doesn't like spaces in user or group names. See My Windows logon name has a space in it, will this cause problems?.

My group name had a space in it, so I changed it in the /etc/group file generated in the authentication fix to an underscore. That didn't work either.

Other postings for the same problem have reported it to result for the virus scanner. I replaced my existing virus scanner (System Center Endpoint Protection) with Sophos. That fixed the problem for me.

I hope this helps.

1

I've had an issue with slow execution of builds for a while on cygwin.

I was forced to update yesterday and ran into the issue of rebaseall simply failing to execute. This forced me to dig into other things and I found a report that Trusteer Rapport/End Point Protection has been known to cause issues with rebaseall, and slow response times. So I removed it, via the normal Windows Uninstall Programs method via Control Panel.

I then did a rebaseall from the dash interface run as admin.

So this means, (win7) from the start menu type dash. The dash shortcut will appear, Right click to run as administrator. Then when it's up, execute :

/usr/bin/rebaseall -v

Go for a coffee... It will sit for a few seconds before it should display output, if it sits and does nothing for more than 5 minutes, you have another issue.

This fixed the rebaseall, but has also massively increased the speed of my build. Worth checking to see if you have it installed, try removing it.

2
  • Can you describe the step(s) that you took in sufficient detail to allow somebody else to do them? … Please do not respond in comments; edit your answer to make it clearer and more complete. May 17, 2019 at 6:02
  • On windows 10, the location for dash was c:\msys64\user\bin\dash.exe. In order to run it as administrator, I had to create a shortcut on my desktop to it. Unfortunately, this did not fix my slow cygwin : (
    – user13743
    Jun 17, 2019 at 23:50
0

I have limited permissions on my machine where this happened. However, as a real hack drop-in substitute, I found that this worked fairly well for me:

find . -maxdepth 1 -ls

It still returned a bit slowly for me, but a lot faster than native ls.

2
  • I got the opposite results. This was the first time I did ls /tmp after a reboot. Note that the second ls is much faster than first ~> time ls /tmp 2>&1 >/dev/null real 0m14.741s ~> time ls /tmp 2>&1 >/dev/null real 0m0.797s ~> time find /tmp -maxdepth 1 -ls 2>&1 >/dev/null real 0m1.598s Jun 17, 2020 at 17:36
  • Sorry for the bad formatting, I am not able to figure out how to add line breaks Jun 17, 2020 at 17:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .