dd-trace-php icon indicating copy to clipboard operation
dd-trace-php copied to clipboard

Investigate if joining meaningfully reduces CPU

Open morrisonlevi opened this issue 2 months ago • 0 comments

Description

The whole-host profiler on one of our benchmarks regularly shows an unusually large amount of CPU spent in shutdown:

Flame chart showing time spent in shutdown.

As you can see, most of it is spent in sched_yield. It's not surprising that this burns CPU (it's roughly what we're asking it to do, spin-loop and wait for the other thread to finish), but what is surprising is that this chunk accounts for roughly 1/3 of all time spent in the profiler in the benchmark.

Perhaps this basically says that our CPU overhead is very low, and that on shutdown we have to wait a few hundred milliseconds for another thread to complete. Waiting for that thread is dominating our time spent.

But I wanted to see what the profiles would look like if I ran this with a traditional thread join. We busy-wait because of an obscure bug we never were able to reproduce.

Results

2025-10-15T16:42:46Z: archetype=enterprise, language=php, framework=symfony, workers=12, loops_cpu=0.01, off_cpu=0.1, profiling=true, rps=100, duration=180, full_host=true
resolved_library_version                         cpu      
-----------------------------------------------  -------  
1.13.0                                           219.866  
1.13.0                                           218.763  
1.13.0                                           219.307  
1.13.0                                           219.288  
1.13.0                                           219.595  
1.13.0                                           219.141  
1.13.0                                           219.684  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.137  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.987  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.364  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.708  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.473  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.513  
1.14.0+24924cb5dfb98309fc785738e0ff587cbd28ce35  217.669  

The version with the commit hash behind it is the branch that uses join instead. As you can see, it does reduce the CPU a bit. I looked at the profiles from the whole-host profiler and shutdown wasn't present at all.

So yes, confirmed that it lowers the CPU. It's not particularly meaningful to use less CPU during shutdown, though.

Reviewer checklist

  • [ ] Test coverage seems ok.
  • [ ] Appropriate labels assigned.

morrisonlevi avatar Oct 15 '25 15:10 morrisonlevi