Skip to content

Instantly share code, notes, and snippets.

@parshap
Last active August 25, 2021 21:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parshap/d523034a3d2768c2f9f07c75fd21d5f5 to your computer and use it in GitHub Desktop.
Save parshap/d523034a3d2768c2f9f07c75fd21d5f5 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