Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cygwin slow file open

Tags:

cygwin

My application uses fopen to open a lot of files. While in linux opening and reading thousand of files doesn't even take a second; in cygwin it takes more than 5 seconds.

I think it is because path conversion functions in cygwin dlls. 'open' function is a bit faster. If I use -mno-cygwin it becomes very fast but I can't use it.

Is there an easy way to make cygwin dlls just open files; without any linux-windows conversion?

like image 376
Erdem Avatar asked Mar 29 '10 12:03

Erdem


1 Answers

It depends on how the system was mounted in the Cygwin environment.

$ mount
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
D: on /cygdrive/d type iso9660 (binary,posix=0,user,noumount,auto)

The mount option "binary" makes it so CRLF <-> LF conversions are not performed on files read from the volume. This is default.

Some things you can do to speed up a Cygwin prompt are the following:

  1. Add the following lines to your ~/.bashrc:
# eliminate long Windows pathnames from the PATH
export PATH='/bin:/usr/bin:/usr/local/bin'

# check the hash before searching the PATH directories
shopt -s checkhash

# do not search the path when .-sourcing a file
shopt -u sourcepath
  1. Disconnect your network drives.

  2. Disable your antivirus, or otherwise exclude Cygwin's folders from its scans.

Thorough antivirus programs scan files for malware as they're opened by programs, and this means it'll be working overtime if your script is opening thousands of files.

  1. Use the option --cache-file="$HOME/.config.cache" when running autotools configure scripts.

This will create a file that holds prerecorded configure discoveries, most of which are usable between software builds. (This is also a good idea when using Linux).

Since the shell seems to be the bottleneck of the Cygwin system, a huge script that relies on starting a large number of processes will take forever and this will cut down on the number of processes it needs to start.

  1. Set up Cygwin's sshd and stop using Windows Command Prompt in favor of PuTTY.

PuTTY responds better to changing text on the screen, as it was built for the more mature CLI interface of *NIX.

like image 143
amphetamachine Avatar answered Nov 18 '22 09:11

amphetamachine