Skip to content

Commit

Permalink
Accurately get hardware cpu count in Vagrantfile.
Browse files Browse the repository at this point in the history
In Vagrantfile replace hack that assumed hyper threading was enabled on
the host and divided ncpu by 2 with methods of getting the actual
hardware core count.
  • Loading branch information
BenTheElder committed May 9, 2015
1 parent 738f403 commit 19224de
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ $kube_provider_boxes = {
}
}

# This stuff is cargo-culted from http://www.stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# Give access to half of all cpu cores on the host. We divide by 2 as we assume
# that users are running with hyperthreads.
# Give access to all physical cpu cores
# Previously cargo-culted from here:
# http://www.stefanwrobel.com/how-to-make-vagrant-performance-not-suck
# Rewritten to actually determine the number of hardware cores instead of assuming
# that the host has hyperthreading enabled.
host = RbConfig::CONFIG['host_os']
if host =~ /darwin/
$vm_cpus = (`sysctl -n hw.ncpu`.to_i/2.0).ceil
$vm_cpus = `sysctl -n hw.physicalcpu`.to_i
elsif host =~ /linux/
$vm_cpus = (`nproc`.to_i/2.0).ceil
$vm_cpus = `cat /proc/cpuinfo | grep 'core id' | wc -l`.to_i
else # sorry Windows folks, I can't help you
$vm_cpus = 2
end
Expand Down

0 comments on commit 19224de

Please sign in to comment.