我正在将一个带有 Grunt 文件监视器的现有项目移植到 Docker 开发容器中。源文件被绑定(bind)安装到容器中,Grunt 监视文件的变化(这可能会被优化,但我目前关心的是:简单地让当前设置在 Docker 中工作)。
在 Mac 上,我遇到了巨大的 CPU 使用率,所以我阅读了 performance tuning guide对于 osxfs。该指南提到了 cached
和 delegated
卷模式。
delegated
的描述说:
the container’s view is authoritative (permit delays before updates on the container appear in the host)
对于缓存
:
[…] provides all the guarantees of the delegated configuration, and some additional guarantees around the visibility of writes performed by containers. As such, cached typically improves the performance of read-heavy workloads, at the cost of some temporary inconsistency between the host and the container.
与哪个设置相比,cached
提高性能?是否从容器的角度来看“读取繁重的工作负载”?
长话短说:对于使用文件监视的开发环境,降低 CPU 使用率的最佳设置是什么? 缓存
还是委托(delegate)
?
最佳答案
好的,我做了一些测试,这是我的结果。设置:
- MacBook Air 11",2014 年初
- macOS 10.12.6
- Docker 17.06.0-ce-mac19 (18663)
- 观看约 1,000 个文件的任务轮询
占用主机 CPU 周期的罪魁祸首进程是 hyperkit
和 com.docker.osxfs
。以下百分比值是五个样本的 CPU 使用率中值:
委托(delegate)
:18.7 % hyperkit + 0.0 % com.docker.osxfs = 18.7 %缓存
:24.3 % hyperkit + 0.1 % com.docker.osxfs = 24.4 %default
又名。一致
:152.0 % hyperkit + 68.9 % com.docker.osxfs = 220.9 % (!)
在功能方面,我没有发现任何差异。当更改容器外的文件时,在这三种情况下, watch 几乎会立即接收到更改。所以我现在要使用 delegated
模式。
关于macos - 带有 Grunt 文件监视的 Docker 卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45737789/