Our label adapter got seven times slower and our CPU graph stayed at forty percent because the time was being stolen
Our carrier label adapters run on eight virtual machines at a hosting provider, a Java service on each. In October the adapter's p95 latency went from about a hundred and twenty milliseconds to nine hundred during business hours, every day, and settled again in the evening.
The CPU panel on our dashboard said the machines were bored. It showed forty percent, the same as it had shown all year. So we looked everywhere else. We profiled the JVM, tuned the garbage collector and opened a ticket with the carrier. Two days went that way.
On the third morning a colleague ran top on one of the gateways and read the CPU line out loud. User and system together were about forty percent. The last figure on that line, st, was thirty eight.
st is steal time. On a virtual machine, a virtual CPU can be ready to run while the hypervisor is busy running something else, usually another customer's machine on the same physical host. The guest kernel cannot use that time, and it is not idle either, so Linux counts it separately, in the steal column of /proc/stat. node_exporter exports it as its own mode of node_cpu_seconds_total, mode="steal". Our panel added up only user and system. Somebody had built it that way years earlier to keep iowait out of the picture, and steal went out with it. Our service was not using more CPU, because while it waited for a turn it was not running at all. Its requests simply waited where no metric of ours could see them.
The provider confirmed that our machines had been moved to a busier host during maintenance at the start of the month. They moved us back, and the next morning steal was under two percent and the p95 was back to a hundred and twenty.
The CPU panel now stacks every mode the kernel reports, user, system, iowait, steal and idle, so they add up to the whole and nothing can leave the picture without being noticed. An alert fires when steal stays above ten percent for fifteen minutes on any machine. The gateways have since moved to the provider's dedicated CPU plan, and the alert is there to tell us if it ever does not.
The graph showed exactly the time our service had used. The problem was in the time it had been waiting for.
– Sergey Shinder