Last active
August 25, 2021 21:34
-
-
Save parshap/d523034a3d2768c2f9f07c75fd21d5f5 to your computer and use it in GitHub Desktop.
Determine number of cpu cores to use in Vagrant
This file contains 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