I remember once I tried to add CPU cores and virtual sockets to a VPS running windows server 2003 and it didn't work and somehow it became unstable and I couldn't use it anymore . Now I'm running Ubuntu 16.04 xenial server version on a VPS and I wonder if it's safe to change the number of cores and virtual sockets from 2-2 to 4-2 ?
This is fine to do. In most hypervisors you can even do this while online given an installed suite of guest tools. If you feel especially wary about it in any way, just "power off" the VM before editing its configuration.
If you're going to be mucking around with changing cores / sockets, then using CPU pinning and mirroring existing architecture will make best use of CPU caches and the like. Other than that, most virtual configurations will float processes as normal tasks. This makes considerations of emulated core / socket architecture pretty meaningless.
You can easily "add" more cores to your server while running by running this script:
#!/bin/bash for CPU in /sys/devices/system/cpu/cpu*/online ; do grep -v -q 0 $CPU || continue echo -n "Bringing $CPU online... " echo 1 > $CPU || exit $? echo OK done
Assuming you already "added" some more cores/socket in vcenter/hyperv/whateveryouuse.
But ofcourse, it is no problem to add more cores and then reboot your VM.