How many cpu cores does each vcpu has?

March 5, 2018 3.6k views
DigitalOcean Ubuntu 16.04

I've deployed the 2 vCPU 4GB RAM droplet, and while setting some configuration I've noticed that it still only has 1 core through 'cpuinfo'.

What is the difference between the 1 vCPU and 2 vCPU if both only have 1 core?

1 comment
  • To contexualize: I'm using Percona to generate a mysql config to better suit the hardware, but since everything is VM here I'm not sure what to put in this field (considering the 2 vcpu 4gb ram):

    "How many CPUs does your system have?

    Enter the total number of CPU cores in your server, including hyperthreading. For example, if you have two 4-core CPUs with hyperthreading, enter 16."

1 Answer
aha MOD March 6, 2018
Accepted Answer

1 vCPU = access to 1 core, 2 vCPUs = access to 2 cores, etc...

At least on Ubuntu/Debian, the /proc/cpuinfo has a separate entry for each CPU core. So when you scan through the file you might see cpu cores: 1 but there is a separate entry for each core. For example:

root@ubuntu-s-2vcpu-4gb-lon1-01:~# cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 63
model name  : Intel(R) Xeon(R) CPU E5-2650L v3 @ 1.80GHz
stepping    : 2
microcode   : 0x1
cpu MHz     : 1799.998
cache size  : 30720 KB
physical id : 0
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single retpoline kaiser vnmi ept fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat
bugs        : cpu_meltdown spectre_v1 spectre_v2
bogomips    : 3599.99
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 63
model name  : Intel(R) Xeon(R) CPU E5-2650L v3 @ 1.80GHz
stepping    : 2
microcode   : 0x1
cpu MHz     : 1799.998
cache size  : 30720 KB
physical id : 1
siblings    : 1
core id     : 0
cpu cores   : 1
apicid      : 1
initial apicid  : 1
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm invpcid_single retpoline kaiser vnmi ept fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt arat
bugs        : cpu_meltdown spectre_v1 spectre_v2
bogomips    : 3599.99
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

Knowing that, some commandline-fu to output the number of cores is:
cat /proc/cpuinfo | grep processor | wc -l

which is just finding the number of lines in cpuinfo with processor. Here's an even more thorough answer: https://askubuntu.com/questions/724228/how-to-find-the-number-of-cpu-cores-including-virtual

Have another answer? Share your knowledge.