问题描述
我一直在运行 drush 脚本(用于 Drupal) 和 Cygwin 在我相对较快的窗口上机器,但我仍然需要等待 大约一分钟 任何 drush 命令(特别是 drush 缓存清除 来执行).
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).
我很确定这与 Cygwin 的速度有关,因为我的开发人员(正在运行 Linux)可以在大约 5 秒内运行这些脚本.
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 在每个终端上使用更多的内存和/或 CPU?
推荐答案
您遇到的问题不是 Cygwin 中的某些任意限制,您可以通过更改设置来消除这些限制.这是 Cygwin 必须工作以获取在其下构建的 POSIX 语义程序的固有方式.
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.
POSIX fork()
系统调用在 Windows 上没有本地等效项,因此 Cygwin 被迫在 一种非常低效的方式.Shell 脚本每次执行外部进程时都会调用 fork()
,这种情况经常发生,因为与我们通常所说的编程语言相比,Shell 脚本语言非常贫乏.外部程序是 shell 脚本完成任何结果的方式.
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.
Cygwin 还存在其他低效问题,但如果您对其进行分析,您可能会发现这是第一大速度.在大多数地方,使用它构建的程序和底层操作系统之间的 Cygwin 层非常薄.Cygwin 的开发人员煞费苦心地保持层尽可能薄,同时仍然提供正确的 POSIX 语义.fork()
调用仿真中当前不常见的厚度是 Microsoft 在其操作系统中添加本机 fork()
类型工具所无法避免的.他们这样做的动机不是很好.
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.
另一种可能性是通过 drush
脚本,看看是否有对外部程序的调用,您可以用 shell 内在函数或更有效的构造替换.我不希望这样做会带来巨大的速度提升,但它具有很好的特性,您也可以在 Linux 方面加快速度.(fork()
在 Linux 上是高效的,但是启动外部程序仍然是一个很大的速度损失,您可能不必像目前那样经常支付费用.)例如:
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 ...
会运行得更快:
if grep -q somepattern $somefile ; then ...
第一个版本可以说更清晰,但它至少需要三个外部程序调用,而对于原始 shell,四个.(你看到所有这些了吗?)替换只需要一个外部程序调用.
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.
这篇关于如何加速 Cygwin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!