Skip to content

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

Open
taegyunkim wants to merge 1 commit into
mainfrom
prof-14213-cpu-sleep-gevent
Open

[python_cpu_sleep_gevent_3.12] add CPU/sleep attribution scenario (PROF-14213)#130
taegyunkim wants to merge 1 commit into
mainfrom
prof-14213-cpu-sleep-gevent

Conversation

@taegyunkim

@taegyunkim taegyunkim commented May 29, 2026

Copy link
Copy Markdown
Contributor

⚠️ Blocked on dd-trace-py 4.10.0 release

This scenario regression-tests the fix in dd-trace-py PR #18222 (fix(profiling): swap on-CPU greenlet to position 0 in unwind_greenlets). That fix is merged into dd-trace-py/main but is not in any released ddtrace tag (latest release is 4.9.0; the fix landed after 4.10.0rc1 was tagged). Until 4.10.0 ships to PyPI, this scenario will fail in CI by ~1.6× total-CPU over-count.

Do not merge this PR until ddtrace==4.10.0 (or any release that contains PR #18222) is on PyPI — merging earlier will break the prof-correctness CI on main and page #profiling-library-pager on every scheduled run.

Track via pip index versions ddtrace --pre or by checking that git tag --contains 0c96beab64 (in dd-trace-py) lists a release tag.

Summary

  • New prof-correctness scenario python_cpu_sleep_gevent_3.12 exercising CPU + sleep alternation in gevent mode (M=4 staggered greenlets) on Python 3.12.
  • Asserts both total CPU (667M ns/wall-sec, ±25%) and cpu_burst self-attribution (80%, ±10%).
  • Acts as a regression check for the gevent over-count bug fixed by dd-trace-py PR #18222 — if it recurs (or ships unreleased), total CPU inflates ~1.6× and busts the ±25% margin.
  • Adds base_images/Dockerfile.python-3.12 (also added by the sibling sync + asyncio 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 gevent run after PR #18222. Same formula as asyncio: M × C / (C + S) = 4 × 0.01 / 0.06 = 0.667 CPU-sec/wall-sec, with _cpu_loop self-time at ~82% in the survey.

Current local-run result (pre-4.10.0 release)

Confirms the regression check fires correctly:

  • .* (total CPU): expected 2.03e+10 ns, actual 32_894_377_000 ns (~62% over) — bug present
  • .*cpu_burst.* (attribution): expected 80%, actual 52% — bug present

These numbers will swing to ≤5% error on both metrics once ddtrace==4.10.0 is released and CI picks it up.

Test plan

  • TEST_SCENARIOS="python_cpu_sleep_gevent_3.12" go test -timeout 10m -v -run TestScenarios passes locally (currently fails — blocked on 4.10.0)
  • CI python.* job passes (currently fails — blocked on 4.10.0)
  • After ddtrace==4.10.0 is on PyPI, verify CI green and re-request review

JIRA: PROF-14213

…OF-14213)

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

Both bounds together act as a regression check for the gevent over-count
bug fixed by dd-trace-py PR #18222 (Finding 3 in the python-cpu-accuracy
survey): if the bug recurs, total CPU would inflate to ~1.07 CPU-sec/wall-sec,
well outside the ±25% margin.

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 14:00
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented May 29, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

prof-correctness | python / docker-scenarios   View in Datadog   GitHub Actions

🔧 Fix in code (Fix with Cursor). 2 assertions failed in TestScenarios: Expected profile values were not within acceptable error margins.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 49569f2 | Docs | Datadog PR Page | Give us feedback!

@KowalskiThomas KowalskiThomas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also check that each Task is attributed the right amount of CPU time?

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