Ray's Knowledge Base
Unlock

Find a scaling limit by dividing CPU time by wall time, then sample thread stacks

RecipeVerified 5 Nov 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.

When to use#

A run with many threads is barely faster than a run with few. Cache and NUMA tests show no cause.

Steps#

  1. Run the tool at 6 and at 48 threads on a warm cache. Record wall time and total CPU time (user plus system).
  2. Divide CPU time by wall time. This is the number of CPUs really used. Here it was 3.4 at 6 threads and 6.2 at 48 threads, so most threads waited.
  3. Count context switches. Here there were 921,000.
  4. Sample the call stack of every thread every few seconds while the tool runs. Group the samples by where the threads wait.
  5. Look for a serial step before the parallel part. Fix it and measure again.

Evidence#

In dftracer-utils index on the 1 GB set, 70% of samples showed idle workers. The cause was a pre-check that opened every file on Lustre and inflated its first gzip member in one serial loop. Running it in parallel gave 22 s at 48 threads, not 60 s, and 14.9 CPUs used. perf stat showed IPC 1.73 and NUMA interleave gave no gain, so those were not the cause.

Also found by searching

  • more threads give almost no speedup
  • how do I find why a parallel program uses only a few CPUs
  • 48 threads only 6 CPUs busy