From bb57fef76b6303c44c51c164c58a0f4f766329d1 Mon Sep 17 00:00:00 2001 From: Nick Ripley Date: Wed, 3 Sep 2025 10:14:01 -0400 Subject: [PATCH] chore(profiling): re-accept interval for memory profile collector [backport 3.12] In #14205 we removed the `_interval` parameter for the `MemoryCollector`. This was a mistake. Now the memory profile collector thread basically spins in a tight loop because the interval is 0. Add that parameter back. Backports #14276 to the 3.12 branch. This was fixed in 3.12.0 but somehow didn't make it to 3.12.1 or 3.12.2 --- ddtrace/profiling/collector/memalloc.py | 4 ++++ ...memalloc-collector-spin-regression-97b4b8093a89c54f.yaml | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 releasenotes/notes/profiling-fix-memalloc-collector-spin-regression-97b4b8093a89c54f.yaml diff --git a/ddtrace/profiling/collector/memalloc.py b/ddtrace/profiling/collector/memalloc.py index ebfb5f0ef2c..72f01b6e842 100644 --- a/ddtrace/profiling/collector/memalloc.py +++ b/ddtrace/profiling/collector/memalloc.py @@ -30,13 +30,17 @@ class MemoryCollector(collector.PeriodicCollector): """Memory allocation collector.""" + _DEFAULT_INTERVAL = 0.5 + def __init__( self, + _interval: float = _DEFAULT_INTERVAL, max_nframe: Optional[int] = None, heap_sample_size: Optional[int] = None, ignore_profiler: Optional[bool] = None, ): super().__init__() + self._interval: float = _interval # TODO make this dynamic based on the 1. interval and 2. the max number of events allowed in the Recorder self.max_nframe: int = max_nframe if max_nframe is not None else config.max_frames self.heap_sample_size: int = heap_sample_size if heap_sample_size is not None else config.heap.sample_size diff --git a/releasenotes/notes/profiling-fix-memalloc-collector-spin-regression-97b4b8093a89c54f.yaml b/releasenotes/notes/profiling-fix-memalloc-collector-spin-regression-97b4b8093a89c54f.yaml new file mode 100644 index 00000000000..ba2b7d7a9f6 --- /dev/null +++ b/releasenotes/notes/profiling-fix-memalloc-collector-spin-regression-97b4b8093a89c54f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + profiling: This fixes a performance regression where the memory profiler's + collector thread would spin in a tight loop, consuming nearly a full CPU + core.