Create contention on purpose and watch steal time appear
Task
Oversubscribe your own host deliberately, then read the metric that reveals contention from inside a guest. The point is to see steal time move, because a number you have watched respond to a cause you created is a number you will recognise on a production system.
Steps
- Give each guest as many vCPUs as your host has LOGICAL CPUs --
nprocon the host, which counts hyperthreads -- so the two guests together are oversubscribed 2:1. Sizing by physical cores on a hyperthreaded host gives two guests that exactly fit the host's threads, and nothing contends. Record the host'snprocand each guest's vCPU count inlab/contend.txt. - With only the first guest running, give it work on every vCPU --
for i in $(seq $(nproc)); do timeout 600 sh -c 'while :; do :; done' & done-- then capture a baseline: runvmstat 1 10and record thestanduscolumns. The first guest must be busy in both captures: steal is time a vCPU WANTED to run and could not, so an idle guest shows almost none however contended the host is. - Start the second guest and saturate it the same way, one busy loop per vCPU. Restart the first guest's loops if their ten minutes have run out.
- Back in the first guest, run
vmstat 1 30again and record thestcolumn. Compare the two captures inlab/contend.txt. - Write one sentence on why the first guest's own CPU utilisation does not explain its slowdown, and one on what you would do about this if it happened on a rented instance.
Verify
grep -Ec '\bst\b|steal' lab/contend.txt
awk '/baseline/,0' lab/contend.txt | grep -Eco '[0-9]+'
grep -Eci 'relocat|stop and start|larger instance|dedicated' lab/contend.txt
The last check is the remedy: recognising steal time is only useful if you know that moving the instance is the first thing to try.
This is an independent study companion for CompTIA Cloud+ CV0-004 and is not produced by or endorsed by CompTIA.