Grunt从Vagrant VM获取所有CPU资源,VM停止响应

时间:2015-09-24 15:01:33

标签: macos gruntjs vagrant virtualbox vagrantfile

我在MacBook Pro上运行了Vagrant / VirtualBox

  OS: Yosemite 10.10.5
  Model Identifier: MacBookPro11,1
  Processor Name:   Intel Core i5
  Processor Speed:  2.4 GHz
  Memory:   8 GB

在几次请求后它停止响应,我甚至无法通过终端haltctrl + c它。我所能做的就是去VirtualBox并关闭它。

已安装的版本:

Vagrant 1.7.4
VirtualBox 5.0.4
grunt-cli v0.1.13
grunt v0.4.5

Vagrantfile:

$ProjectName = 'projectdev'

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "ubuntu/trusty64"
  config.vm.box_url = "https://atlas.hashicorp.com/ubuntu/boxes/trusty64"
  config.vm.hostname = "#{$ProjectName}"
  config.vm.network "forwarded_port", guest: 80, host: 8888
  config.vm.network "forwarded_port", guest: 5432, host: 15432
  config.vm.network :private_network, ip: "10.0.0.10"
  config.vm.synced_folder ".", "/vagrant"
  config.ssh.username = 'vagrant'
  config.ssh.password = 'vagrant'
  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end
  #config.vm.provider "virtualbox" do |v|
    #v.gui = true
  #end


  config.vm.provision :shell, path: "infra/bootstrap.sh"

end

Vagrant::Config.run do |config|

  #config.vm.share_folder "bootstrap", "/mnt/bootstrap", ".", :create => true
  config.vm.provision :shell, :path => "infra/postgresql.sh"

  # PostgreSQL Server port forwarding
  #config.vm.forward_port 5432, 15432
end

这是top如何看待它停止响应的时刻

top - 18:58:37 up 3 min,  2 users,  load average: 3.55, 1.31, 0.48
Tasks: 140 total,   2 running, 138 sleeping,   0 stopped,   0 zombie
%Cpu(s):  2.6 us, 74.3 sy,  0.0 ni, 22.9 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st
KiB Mem:   2049900 total,   930712 used,  1119188 free,    19608 buffers
KiB Swap:        0 total,        0 used,        0 free.   170280 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                           
 1784 vagrant   20   0  756756 104628   7476 R 150.7  5.1   2:09.88 grunt                                             
   32 root      20   0       0      0      0 S   0.3  0.0   0:00.14 kworker/0:1                                       
 1921 vagrant   20   0  107696   2184   1180 S   0.3  0.1   0:00.06 sshd                                              
 1936 vagrant   20   0   23692   1700   1168 R   0.3  0.1   0:00.11 top                                               
    1 root      20   0   33640   2996   1492 S   0.0  0.1   0:01.26 init    

Grunt是否有什么需要花费更少的资源而不是杀死我的VM?

1 个答案:

答案 0 :(得分:0)

所以我似乎找到了问题的答案!

  1. 在MAC上,您应该打开NFS SYNCED FOLDERS
  2. 使用所有CPU核心
  3. 不要吝啬memmory for Virtual Machine;)
  4. 另外,我还没有尝试过这个,但也可能是一个很好的优化! grunt-watch-slow