A Long Wait Can Use Little CPU Time

Elapsed time includes running and waiting. CPU time estimates execution time charged to the process or its threads under the measurement interface.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a typical command
  2. Choose the right optimization target
  3. Split total elapsed time into work and waiting
  4. Investigate the waited-on dependency

Trace a typical command

A job starts a read, waits 900 milliseconds, then computes for 100 milliseconds. Its total elapsed time can be about a second while CPU use reflects roughly the calculation plus overhead. See blocked and running states.

Choose the right optimization target

Improving the calculation by half can save only part of the elapsed time if the read still dominates. Measuring cost can separate these observed components.[1]

Split total elapsed time into work and waiting

A process spends one hundred milliseconds computing and then waits nine hundred milliseconds for a response. Its elapsed time is about one second while its own CPU time is near one tenth of a second. The missing elapsed time can be ordinary blocking. See ready, running and blocked states.

Compute: 100 ms
Wait for I/O: roughly 900 ms
Elapsed: roughly 1000 ms
Busy CPU time for this single-threaded model: roughly 100 ms

Investigate the waited-on dependency

Two waits with similar total durations may come from different devices, queues or services. Time operations at boundaries and correlate with the relevant downstream events. Distinguish a blocked task from one ready but unscheduled.

References

  1. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩