Skip to content

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

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

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

DefaultCompositePerformanceCollector samples CPU and memory every 100ms for running transactions and profiles. It did this on a java.util.Timer, which schedules on the wall clock: after a backward clock step, sampling stopped until the clock caught up. The 30s collection timeout runs in the same task, so it stalled too.

The loop now runs on options.getTimerExecutorService(), which schedules on System.nanoTime() and is already used by SentryTracer for its idle and deadline timeouts. That executor only has a one-shot schedule(), so each run schedules the next one:

start():
  schedule(setup collectors, 0ms)
  schedule(collectAndReschedule(generation), 100ms)

collectAndReschedule(myGeneration):
  sample collectors, append to every running transaction/profile
  stop transactions past the 30s timeout   // may call close()
  if myGeneration == generation:           // under timerLock
    schedule(collectAndReschedule(myGeneration), 100ms)

close():
  generation++                             // under timerLock
  pendingRun.cancel(false)

The generation counter is the part worth reviewing. cancel() can't stop a run that is already executing, and that run may itself close the collector by timing out the last transaction. Without the check it would reschedule a chain that was just cancelled.

Only scheduling changes. Samples are stamped and computed as before, so no metric or API changes. The collector also no longer creates a thread for each burst of transactions.

Based on #5816, which made the same change and was closed without review. The 30s timeout fix in this class (#6101) is only on 9.x.x, so expect a small conflict the next time main is merged into it.

#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

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

None yet

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