Last active
February 12, 2018 18:49
-
-
Save wizardishungry/2660808 to your computer and use it in GitHub Desktop.
Vagrant snippet to set VirtualBox guest CPU count to the number of host cores on Linux or OS X (broken 2018)
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
gem 'concurrent' |
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
require 'concurrent' | |
config.vm.provider "virtualbox" do |vb| | |
v.cpus = Concurrent.physical_processor_count | |
end |
You can use this snippet:
grep "^processor" /proc/cpuinfo | wc -l
instead of:
awk "/^processor/ {++n} END {print n}" /proc/cpuinfo 2> /dev/null || sh -c 'sysctl hw.logicalcpu 2> /dev/null || echo ": 2"' | awk \'{print \$2}\'
Great stuff.
You can use this to get the count of physical cores only
grep "^core id" /proc/cpuinfo | sort | uniq | wc -l | tr -d '\n'
or just use nproc
.to_i :)
cpus=`nproc`.to_i
cpus = cpus / 2
This becomes problematic when cpus=1. What shall I do to prevent cpus to return 0? Is there some kind of min/max functions somewhere?
updated for 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works well :)