ContentsThe library

What Happens While You Wait

Four Seconds of Wall Clock, Half a Second of Work, and Where the Rest Went

Last timeBeing Interrupted

The system keeps an account of your process whether you ask or not. Here is how to read it, how to attribute a slowdown to the processor, a device or a lock, and what the numbers cannot tell you.

The account that always balances

Run anything under a timer that reports three numbers rather than one and the

shape of the problem is usually visible immediately.

FIG 1The three numbers, and what is left over
elapsed time, the wall clock
time the processor spent executing your code
time the processor spent in kernel code on your behalf
time your process was not running at all, which nobody reports directly
The first three are measured and the fourth is a subtraction, which is the most useful arithmetic in this course. A program with four seconds elapsed, half a second of your code and a tenth of a second of kernel code spent three and a half seconds not running, and no amount of looking at your own code will explain where they went. Note also what a large second term means: time in the kernel on your behalf is still your time, and a program spending most of its charged time there is usually making far too many requests.

Two refinements matter. On a machine with several processors, the first two

terms can exceed the elapsed time, because they are summed across threads: four

seconds elapsed with twelve seconds of charged time means three processors were

busy throughout. And the second term is charged to you for work the kernel did

because you asked, which includes the crossings from the second lesson, so an

unexpectedly large second term is very often a request-count problem.

What the system will tell you

Four instruments, each answering one question well.

The per-process counters give the split above, plus the page fault counts and,

crucially, two switch counts: voluntary, meaning the process gave up the

processor because it blocked, and involuntary, meaning it was preempted. That

pair is the most under-used diagnostic on the machine.

A call trace shows each request the process made, in order, with how long each

took. It answers which device, which file, which address, and it is the fastest

way to find a program making a hundred thousand tiny requests where it could

have made ten.

System-wide utilisation says whether the machine is short of anything, which is

a different question from whether your process is slow, and confusing the two

is the commonest mistake in this area.

And a sampling profiler says where in your own code the charged time went,

which matters only if the first term above was large. A profiler pointed at a

program that is blocked tells you nothing, beautifully.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Your Program Cannot Read a File, and Never Could
  2. 02Two Hundred Times the Price, for a Line That Looks the Sameopening only
  3. 03Your Program Is the Small Part of Your Processopening only
  4. 04The Program That Waits Gets Served First, and It Is Not Being Rewardedopening only
  5. 05Not Running Is Two Different Problems With One Symptomopening only
  6. 06Ten Thousand Connections, One Thread, and One Thing It Still Cannot Doopening only
  7. 07Your Handler Runs Between Two Instructions You Did Not Chooseopening only
  8. 08Four Seconds of Wall Clock, Half a Second of Work, and Where the Rest Wentyou are here

Read alongside