Skip to content

ref(core): Sample performance data on the timer executor (JAVA-837) - #6589

Merged
runningcode merged 3 commits into
mainfrom
no/java-837-collector-timer
Nov 30, 2026
Merged

runningcode merged 3 commits into
mainfrom
no/java-837-collector-timer

Conversation

@runningcode

@runningcode runningcode commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

DefaultCompositePerformanceCollector sampled CPU and memory on a java.util.Timer, which uses the wall clock, so sampling stopped after a backward clock step. It now runs on options.getTimerExecutorService(), which uses System.nanoTime(). Each run schedules the next one 100ms later, the same fixed delay as before.

Worth reviewing:

  • generation keeps a run that is already executing from rescheduling after close(). The run can trigger that close() itself by timing out the last transaction.
  • The setup task schedules the first collect. Otherwise a busy shared timer thread could run setup() and collect() back to back, giving AndroidCpuCollector a near-zero interval.

Based on #5816, which was closed without review.

#skip-changelog

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Nov 12, 2026

Copy link
Copy Markdown

JAVA-837

@sentry

sentry Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.66.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 356cd6e.

Main concerns: reach, host performance, data sent to Sentry.

This label is a hint for reviewers, not an approval.

@runningcode
runningcode marked this pull request as ready for review November 23, 2026 10:26
@runningcode
runningcode requested review from a team and adinauer as code owners November 23, 2026 10:26
@runningcode
runningcode requested review from markushi and romtsn and removed request for a team November 23, 2026 10:26
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dd1a717. Configure here.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 25, 2026

@romtsn romtsn 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.

one comment re. tests but LGTM otherwise!

There's one more behaviour change which is the executor.scheduleWithFixedDelay schedules the next read after the task has finished, whereas previously, the Timer would compute the next run before the task and schedule it exactly 100ms after scheduling the first task. However, I think the new approach is the right one and it does not break anything, and it also saves our shared executor from exhaustion.

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 26, 2026
@runningcode
runningcode force-pushed the no/java-837-collector-timer branch from 2f9f42d to bcdcd0a Compare November 30, 2026 10:32
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 30, 2026
@runningcode
runningcode enabled auto-merge (squash) November 30, 2026 12:34
runningcode and others added 3 commits November 30, 2026 14:39
DefaultCompositePerformanceCollector sampled CPU and memory every 100ms
on a java.util.Timer, the last one in the SDK. Timer schedules on the
wall clock, so a backward clock step stopped sampling, and the 30s
collection budget check that runs in the same task, until the clock
caught back up.

The loop now runs on options.getTimerExecutorService(), which schedules
on System.nanoTime(). The executor only has one-shot schedule(), so each
run reschedules itself. A generation counter, bumped in close(), stops a
run that is already in flight from rescheduling a cancelled chain.

Based on #5816.

Fixes JAVA-837

Co-Authored-By: Claude Opus 5.5 <[email protected]>
setup() and the first collect() were separate tasks on the shared timer thread, so a busy thread made them run back to back and AndroidCpuCollector divided by a near-zero interval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tests ran collection on a real executor and slept, so they only proved
a 100ms delay was requested, and a collector started for a string id kept
running until the JVM exited. A hand-advanced fake executor lets the tests
count each collect and leaves nothing running after a test ends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@runningcode
runningcode force-pushed the no/java-837-collector-timer branch from bcdcd0a to 356cd6e Compare November 30, 2026 13:39
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 30, 2026
@runningcode
runningcode merged commit 683d150 into main Nov 30, 2026
51 checks passed
@runningcode
runningcode deleted the no/java-837-collector-timer branch November 30, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move the performance collector's sampling loop off java.util.Timer

2 participants