Skip to content

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

Open
runningcode wants to merge 1 commit into
mainfrom
no/java-837-collector-timer
Open

runningcode wants to merge 1 commit into
mainfrom
no/java-837-collector-timer

Conversation

@runningcode

@runningcode runningcode commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

After a backward wall-clock step, DefaultCompositePerformanceCollector stopped sampling CPU and memory for running transactions and profiles until the clock caught up. It scheduled on a java.util.Timer, which uses the wall clock. It now schedules on options.getTimerExecutorService(), which uses System.nanoTime() and is already used by SentryTracer for its idle and deadline timeouts. This was the last java.util.Timer in the SDK.

The executor only has a one-shot schedule(), so each run schedules the next one. This keeps the old fixed-delay behavior, because Timer.schedule(task, delay, period) is fixed-delay, not fixed-rate.

Worth reviewing: the generation counter. close() can't cancel a run that is already executing, and that run may itself call close() by timing out the last transaction. A run only schedules the next one if generation hasn't changed since it was scheduled. collector times out after 30 seconds fails without this check.

Not changed:

  • Sample timestamps and the 30s timeout still read options.getDateProvider(). On the JVM that's the wall clock, so a backward step still extends the timeout. ref(core): Measure the performance-collection budget on a monotonic ticker (JAVA-579) #6101 moves the timeout to a monotonic ticker on 9.x.x. Expect a small conflict the next time main is merged into it.
  • Collection now shares one thread with tracer timeouts, the rate limiter and the Android session-end timer. Each run is a /proc/self/stat read plus Runtime stats.

Based on #5816, which made the same change and 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.64.0 (1) release

⚙️ sentry-android Build Distribution Settings

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 <noreply@anthropic.com>
@runningcode
runningcode force-pushed the no/java-837-collector-timer branch from 8a0aeef to dd1a717 Compare November 17, 2026 10:30
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit dd1a717.

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.

.getTimerExecutorService()
.schedule(
() -> collectAndReschedule(currentGeneration),
TRANSACTION_COLLECTION_INTERVAL_MILLIS);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setup and collect can collapse

Medium Severity

setup() and the first collect() are queued as two independent tasks (delay 0 and 100ms) on the shared single-thread timer executor. A long task already on that thread, such as an idle-timeout finish(), can make both due before either runs, so they execute back-to-back. AndroidCpuCollector then divides by a near-zero interval and can emit huge or non-finite CPU percentages.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bugbot

Reviewed by Cursor Bugbot for commit dd1a717. Configure here.

This branch has not been deployed

No deployments
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

1 participant