The Short Answer
A vCPU is the unit of processing power a virtual machine receives. The guest operating system counts it as one CPU and runs one thread of work on it at a time. The hypervisor runs each vCPU on a physical processor thread whenever the guest has work to do, and gives that thread to another vCPU when it does not. A vCPU is therefore not a piece of hardware set aside, but a scheduled share of one.
Sockets, Cores, Threads, and vCPUs
| Term | Meaning |
|---|---|
| Socket | One physical processor package. |
| Core | An independent processing unit inside it. |
| Thread | A logical CPU; with SMT, one core usually runs two. |
| vCPU | A virtual CPU scheduled on a thread. |
A processor with 16 cores and two threads per core shows 32 logical CPUs to the host operating system. SMT is the general name; Intel calls it Hyper-Threading. Two threads on one core share that core's execution units, so they do not give twice the speed of one.
How a Hypervisor Schedules vCPUs
With KVM, each vCPU is a thread of the virtual machine's process on the host. The host's scheduler places that thread on any logical CPU that is available, the same way it places other processes. An idle vCPU uses almost no host time.
Because most virtual machines are idle much of the time, the total number of vCPUs on a host can be higher than the number of logical CPUs. This is called overcommitment. It works as long as the guests do not all need full power at once; when they do, some vCPUs wait for a turn. A hypervisor can also pin a vCPU to a chosen physical thread, so that vCPU always runs there; keeping other work off that thread is a separate setting.
Count the vCPUs Inside Your Server
nproc
lscpu
nproc prints the number of CPUs available to you. lscpu shows more detail:
- CPU(s): the number of vCPUs.
- Model name: the processor model the hypervisor reports.
- Thread(s) per core, Core(s) per socket, Socket(s): the topology presented to the guest.
- Hypervisor vendor: for example KVM; the line appears only when lscpu detects a hypervisor.
The topology inside a virtual machine is whatever the hypervisor chooses to present. "Thread(s) per core: 1" in a guest does not tell you whether the host uses SMT, and "Socket(s): 2" does not mean two physical processors serve you.
Measure Steal Time
Steal time is the share of time a vCPU was ready to run but had to wait for the host. It is the one scheduling effect you can see from inside the guest:
vmstat 1 5
Read the st column, which vmstat describes as time stolen from a virtual machine. In top, the same value appears as st in the CPU line. A value that stays near zero means your vCPUs get the host time they ask for. What higher values mean and what to do about them is covered in CPU steal time on a VPS.
vCPU vs Physical Core in Practice
- Single-thread speed: depends on the physical processor model and its clock, which
lscpushows. - Shared cores: a vCPU that runs on one hardware thread shares the core with whatever runs on the other thread.
- Parallel work: more vCPUs help only if the software runs several threads or processes, such as a web server with many workers or a database under many connections.
- Dedicated hardware: on a bare-metal server there is no hypervisor, and every core and thread is yours. See what is a bare metal server.
How Many vCPUs Do You Need?
Compare the load average with the output of nproc. A load that stays above the number of vCPUs for long periods means work is queuing for the processor; a load far below it means processor power is not your limit. The numbers are explained in Linux load average. Memory and disk speed limit many servers before the processor does, so check them as well before you add vCPUs.