Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow load time of bash in cygwin

At the moment bash takes about 2 seconds to load. I have ran bash with -x flag and I am seeing the output and it seems as though PATH is being loaded many times in cygwin. The funny thing is I use the same file in linux environment, but it works fine, without the reload problem. Could the following cause the problem?

if [ `uname -o` = "Cygwin" ]; then
    ....
fi
like image 924
Forethinker Avatar asked Mar 20 '13 22:03

Forethinker


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.

Does Cygwin use Bash?

The Cygwin installation creates a Bash shell along with a UNIX environment by which you can compile and run UNIX-like programs. Using this one can even create an emulated X server on your windows box and run UNIX-like GUI software tools.


2 Answers

As you've noted in your answer, the problem is Cygwin's bash-completion package. The quick and easy fix is to disable bash-completion, and the correct way to do that is to run Cygwin's setup.exe (download it again if you need to) and select to uninstall that package.

The longer solution is to work through the files in /etc/bash_completion.d and disable the ones you don't need. On my system, the biggest culprits for slowing down Bash's load time (mailman, shadow, dsniff and e2fsprogs) all did exactly nothing, since the tools they were created to complete weren't installed.

If you rename a file in /etc/bash_completion.d to have a .bak extension, it'll stop that script being loaded. Having disabled all but a select 37 scripts on one of my systems in that manner, I've cut the average time for bash_completion to load by 95% (6.5 seconds to 0.3 seconds).

like image 139
me_and Avatar answered Oct 19 '22 15:10

me_and


In my case that was windows domain controller. I did this to find the issue:

I started with a simple, windows cmd.exe and the, typed this:
c:\cygwin\bin\strace.exe c:\cygwin\bin\bash

In my case, I noticed a following sequence:

    218   12134 [main] bash 11304 transport_layer_pipes::connect: Try to connect to named pipe: \\.\pipe\cygwin-c5e39b7a9d22bafb-lpc
     45   12179 [main] bash 11304 transport_layer_pipes::connect: Error opening the pipe (2)
     39   12218 [main] bash 11304 client_request::make_request: cygserver un-available
1404719 1416937 [main] bash 11304 pwdgrp::fetch_account_from_windows: line: <CENSORED_GROUP_ID_#1>
    495 1417432 [main] bash 11304 pwdgrp::fetch_account_from_windows: line: <CENSORED_GROUP_ID_#2>
    380 1417812 [main] bash 11304 pwdgrp::fetch_account_from_windows: line: <CENSORED_GROUP_ID_#3>

    etc...

The key thing was identifying the client_request::make_request: cygserver un-available line. You can see, how after that, cygwin tries to fetch every single group from windows, and execution times go crazy.

A quick google revealed what a cygserver is: https://cygwin.com/cygwin-ug-net/using-cygserver.html

Cygserver is a program which is designed to run as a background service. It provides Cygwin applications with services which require security arbitration or which need to persist while no other cygwin application is running.

The solution was, to run the cygserver-config and then net start cygserver to start the Windows service. Cygwin startup times dropped significantly after that.

like image 22
npe Avatar answered Oct 19 '22 16:10

npe