Create contention on purpose and watch steal time appear

short · 40 min · Objective 1.2

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

  1. Give each guest as many vCPUs as your host has LOGICAL CPUs -- nproc on 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's nproc and each guest's vCPU count in lab/contend.txt.
  2. 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: run vmstat 1 10 and record the st and us columns. 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.
  3. 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.
  4. Back in the first guest, run vmstat 1 30 again and record the st column. Compare the two captures in lab/contend.txt.
  5. 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.