简体   繁体   English

如何加速Cygwin?

[英]How to speed up Cygwin?

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). 我一直在我的相对较快的Windows机器上运行Cygwin的 drush脚本(对于Drupal ),但是我仍需要等待大约一分钟来执行任何drush命令(特别是drush cache clear执行)。

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. 我很确定它与Cygwin的速度有关,因为我的开发人员(运行Linux)可以在大约5秒内运行这些脚本。

Is there a way to make Cygwin use more memory and/or CPU per terminal? 有没有办法让Cygwin每个终端使用更多的内存和/或CPU?

The problem you're running into is not some arbitrary limit in Cygwin that you can make go away with a settings change. 您遇到的问题不是Cygwin中的任意限制,您可以通过设置更改消除这些限制。 It's an inherent aspect of the way Cygwin has to work to get the POSIX semantics programs built under it expect. 这是Cygwin必须努力获得在其下构建的POSIX语义程序的方式的固有方面。

The POSIX fork() system call has no native equivalent on Windows, so Cygwin is forced to emulate it in a very inefficient way . POSIX fork()系统调用在Windows上没有本机等价物,因此Cygwin被迫以非常低效的方式模拟它。 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. Shell脚本每次执行外部进程时都会调用fork() ,因为shell脚本语言相对于我们通常所说的编程语言而言非常贫乏,所以这种情况发生了很多。 External programs are how shell scripts get anything of consequence done. 外部程序是shell脚本如何完成任何后果的。

There are other inefficiencies in Cygwin, though if you profiled it, you'd probably find that that's the number one speed hit. Cygwin还有其他低效率,但如果你对它进行了分析,你可能会发现这是速度最快的。 In most places, the Cygwin layer between a program built using it and the underlying OS is pretty thin. 在大多数地方,使用它构建的程序和底层操作系统之间的Cygwin层非常薄。 The developers of Cygwin take a lot of pains to keep the layer as thin as possible while still providing correct POSIX semantics. Cygwin的开发人员需要花费很多精力来保持图层尽可能薄,同时仍然提供正确的POSIX语义。 The current uncommon thickness in the fork() call emulation is unavoidable short of Microsoft adding a native fork() type facility to their OS. fork()调用仿真中当前不常见的厚度是不可避免的,因为Microsoft在其操作系统中添加了本机fork()类型工具。 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. 另一种可能性是通过drush脚本查看是否有对外部程序的调用,您可以用shell内在函数或更高效的构造替换它们。 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. 我不希望通过这样做可以大幅度提高速度,但它具有很好的性能,你也可以加速Linux方面的速度。 ( 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: fork()在Linux上是高效的,但启动外部程序仍然是一个很大的速度,你可能不需要像现在这样经常付费。)例如:

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 . 第一个版本可以说是更清晰,但它至少需要三个外部程序调用,而原始shell需要四个 (Do you see all of them?) The replacement requires only one external program invocation. (你看到了所有这些吗?)替换只需要一个外部程序调用。

Also look at things that slow down Cygwin startup: 还要看看减缓Cygwin启动速度的事情:

  • Trim down your Windows PATH (to the bare bones like %SystemRoot%\\system32;%SystemRoot%) 修剪你的Windows PATH(像%SystemRoot%\\ system32;%SystemRoot%这样的裸机)
  • Remove things you don't need from bashrc and bash_profile 从bashrc和bash_profile中删除不需要的内容
  • Move things you only need in your terminal window from bashrc to bash_profile 将您在终端窗口中只需要的东西从bashrc移动到bash_profile
  • One surprisingly large time suck in Cygwin is Bash completion. Cygwin的一个令人惊讶的大时间吮吸是Bash完成。 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 . 并且,如上所述,从bash_profile而不是bashrc

You can give Cygwin a higher priority. 你可以给Cygwin一个更高的优先级。

Write a new batch file, for example, "cygstart.bat" with the following content: 编写一个新的批处理文件,例如“cygstart.bat”,其中包含以下内容:

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

The /high switch gives the shell a higher process priority. /high开关为shell提供了更高的进程优先级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM