Skip to content

[python_cpu_sleep_asyncio_3.12] add CPU/sleep attribution scenario (PROF-14213) - #129

Open
taegyunkim wants to merge 4 commits into
mainfrom
prof-14213-cpu-sleep-asyncio
Open

[python_cpu_sleep_asyncio_3.12] add CPU/sleep attribution scenario (PROF-14213)#129
taegyunkim wants to merge 4 commits into
mainfrom
prof-14213-cpu-sleep-asyncio

Conversation

@taegyunkim

@taegyunkim taegyunkim commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • New prof-correctness scenario python_cpu_sleep_asyncio_3.12 exercising CPU + sleep alternation in asyncio mode (M=4 staggered slots) on Python 3.12.
  • Asserts total CPU rate: 667_000_000 ns/wall-sec, ±25%.
  • Asserts CPU work attribution: cpu_burst accounts for ~80% of CPU time, ±10%.
  • Asserts per-asyncio-task CPU attribution: Task-2 through Task-5 each account for ~25% of CPU time, ±15%, on MainThread.
  • Adds base_images/Dockerfile.python-3.12 (also added by the sibling sync + gevent PRs; rebase whichever lands second/third).

Why Python 3.12

Python 3.12 is the most widely deployed version among dd-trace-py customers and the version Datadog runs internally, so the regression check exercises the same combination most users see in production.

Why these bounds

Based on the python-cpu-accuracy survey (DataDog/experimental, users/taegyun.kim/python-cpu-accuracy) adaptive-off asyncio run, which measured _cpu_loop self-time at ~81% with total CPU ~40 s/min on 4 staggered slots × 10 ms / 50 ms.

Formula: M × C / (C + S) = 4 × 0.01 / 0.06 = 0.667 CPU-sec/wall-sec.

The per-task assertion verifies that CPU time is split across the four asyncio tasks rather than being attributed to only one task. GitHub Actions showed more scheduler/sample noise for individual task labels (for example 12% / 24% / 37% / 24%), so the per-task budget is ±15% while still catching a large attribution skew.

Latest local run:

  • .* total CPU: expected ~20.2s, actual 19.8s (2.3% error)
  • .*cpu_burst.*: expected 80%, actual 82% (2% error)
  • per-task attribution: Task-2=15%, Task-3=18%, Task-4=40%, Task-5=24% (all within ±15%)

Test plan

  • go test -run TestSchemaValidation ./...
  • TEST_SCENARIOS="python_cpu_sleep_asyncio_3.12" go test -timeout 10m -v -run TestScenarios ./...
  • CI python.* job passes

JIRA: PROF-14213

…ROF-14213)

New scenario that alternates 10 ms CPU bursts with 50 ms sleeps in
asyncio mode with 4 concurrent staggered slots, asserting on (a) total
CPU consumed (667M ns/wall-sec, ±25%) and (b) cpu_burst self-attribution
as % of cpu-time profile (80% ±10%).

The 80% baseline comes from the python-cpu-accuracy survey's adaptive-off
asyncio runs: 4 staggered slots × 10 ms CPU × 50 ms sleep gives 40 s/min
of CPU, and ~81% of that attributed to _cpu_loop in the survey.

Adaptive sampling is disabled (_DD_PROFILING_STACK_ADAPTIVE_SAMPLING_ENABLED=0).

Also adds base_images/Dockerfile.python-3.12.
@taegyunkim
taegyunkim requested a review from a team as a code owner May 29, 2026 13:52
Comment thread scenarios/python_cpu_sleep_asyncio_3.12/expected_profile.json
@datadog-prod-us1-3

This comment has been minimized.

@taegyunkim
taegyunkim requested a review from KowalskiThomas June 3, 2026 14:17
@taegyunkim

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants