-
-
Save havenwood/7079afe5a0f78ad1275bcbbe0d136d5f to your computer and use it in GitHub Desktop.
Determine number of cpu cores to use in Vagrant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Determines how many cpus the virtual machine should be given. Uses half of | |
# what's available on the host with a default of 4. | |
def numvcpus | |
begin | |
os_cpu_cores / 2 | |
rescue | |
4 | |
end | |
end | |
# Get the number of logical cpu cores. | |
def os_cpu_cores | |
case RbConfig::CONFIG['host_os'] | |
when /darwin/ | |
Integer(`sysctl -n hw.ncpu`) | |
when /linux/ | |
Integer(`cat /proc/cpuinfo | grep processor | wc -l`) | |
else | |
raise StandardError, "Unsupported platform" | |
end | |
end | |
puts "Use %s cores.", numvcpus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment