Skip to content

Instantly share code, notes, and snippets.

@havenwood
Forked from parshap/cpus.rb
Created June 23, 2016 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/7079afe5a0f78ad1275bcbbe0d136d5f to your computer and use it in GitHub Desktop.
Save havenwood/7079afe5a0f78ad1275bcbbe0d136d5f to your computer and use it in GitHub Desktop.
Determine number of cpu cores to use in Vagrant
# 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