19

I have been running drush scripts (for Drupal) with Cygwin on my relatively fast windows machine, but I still have to wait about a minute for any drush command (specifically drush cache clear to execute).

I'm quite sure it has something to do with the speed of Cygwin since my fellow developers (who are running Linux) can run these scripts in about 5 seconds.

Is there a way to make Cygwin use more memory and/or CPU per terminal?

6
  • 8
    Stick an ubuntu CD in? :)
    – Rimian
    Commented Mar 25, 2010 at 3:27
  • 2
    This question presumes that the performance of windows drush is equivalent to linux drush and is memory or cpu limited. That's not a self-evident assumption: it could simply be slower.
    – msw
    Commented Mar 25, 2010 at 3:30
  • 3
    Give virtualization a try... with hardware support it can be truly amazing
    – Sam Post
    Commented Mar 25, 2010 at 3:57
  • So you're saying I should change my entire development environment over to a virtual machine? Or are you saying that I can execute the drush command through a virtual linux that will clear the cache on the windows side?
    – tester
    Commented Mar 25, 2010 at 4:06
  • If it's just cache clear, you could just run a curl command from cygwyn that corresponds to the menu callback which empties cache in Drupal. I know this isn't a solution but it may save you some time while you work out the real fix.
    – Rimian
    Commented Mar 25, 2010 at 9:57

3 Answers 3

32

The problem you're running into is not some arbitrary limit in Cygwin that you can make go away with a settings change. It's an inherent aspect of the way Cygwin has to work to get the POSIX semantics programs built under it expect.

The POSIX fork() system call has no native equivalent on Windows, so Cygwin is forced to emulate it in a very inefficient way. Shell scripts cause a call to fork() every time they execute an external process, which happens quite a lot since the shell script languages are so impoverished relative to what we'd normally call a programming language. External programs are how shell scripts get anything of consequence done.

There are other inefficiencies in Cygwin, though if you profiled it, you'd probably find that that's the number one speed hit. In most places, the Cygwin layer between a program built using it and the underlying OS is pretty thin. The developers of Cygwin take a lot of pains to keep the layer as thin as possible while still providing correct POSIX semantics. The current uncommon thickness in the fork() call emulation is unavoidable short of Microsoft adding a native fork() type facility to their OS. Their incentives to do that aren't very good.

The solutions posted above as comments aren't bad.

Another possibility is to go through the drush script and see if there are calls to external programs you can replace with shell intrinsics or more efficient constructs. I wouldn't expect a huge speed improvement by doing that, but it has the nice property that you'll speed things up on the Linux side as well. (fork() is efficient on Linux, but starting external programs is still a big speed hit that you may not have to pay as often as you currently do.) For instance:

numlines=`grep somepattern $somefile | wc -l`
if [ $numlines -gt 0 ] ; then ...

would run faster as:

if grep -q somepattern $somefile ; then ...

The first version is arguably clearer, but it requires at least three external program invocations, and with primitive shells, four. (Do you see all of them?) The replacement requires only one external program invocation.

11

Also look at things that slow down Cygwin startup:

  • 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. If you are using it (and you should because it's great), only source completion for the commands you need (rather than all of them which used to be the default). And, as mentioned above, source them from bash_profile, not bashrc.
1
  • 5
    Trimming down the PATH can make a huge difference. :)
    – Rufflewind
    Commented May 9, 2014 at 6:38
6

You can give Cygwin a higher priority.

Write a new batch file, for example, "cygstart.bat" with the following content:

start "Cygwin" /high C:\cygwin\Cygwin.bat

The /high switch gives the shell a higher process priority.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.