Adding more CPU-cores without rebooting you Linux-server
This assumes that you are running your Linuxsystem as a virtual server on VMWare, KVM, XEN or AHV with CPU Hotplug enabled.
From time to time, I have been in need of extra CPU-power for various reasons. It might be that someone suddenly got alot of traffic to their PHP-based website, or they want to add more containers but loosing the time and uptime that comes with a reboot it not an option.
Luckily, there is solutions for that!
- First of all, add the cores to your VM via your hypervisor.
- Second, we need to tell the kernel that there is more cores available for use, we can do that by using this simple script:
for f in /sys/devices/system/cpu/cpu*/online ; do
grep -v -q 0 $f || continue
echo -n "Bringing $f online... "
echo 1 > $f || continue
echo OK
done
Done, you can now verify that you have added more cores to your system, using for example – htop