Repository navigation
ref(core): Sample performance data on the timer executor (JAVA-837) - #6589
runningcode wants to merge 3 commits into
Conversation
📲 Install BuildsAndroid
|
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>
8a0aeef to
dd1a717
Compare
PR risk: mediumFor commit Main concerns: reach, host performance, data sent to Sentry. This label is a hint for reviewers, not an approval. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
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 <noreply@anthropic.com>
| collector.start(fixture.id1) | ||
| verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100)) | ||
| Thread.sleep(300) | ||
| assertTrue(fixture.executorService.scheduledDelays.contains(100L)) |
There was a problem hiding this comment.
I think this only tests that collection runs once but not "every 100 ms". Can we change it to a fake executor that we advance by hand and then we could assert it multiple times?
There's also a pre-existing problem that we are leaking the executor/timer because the collector started for a string id has no timeout, so the collectors kept running until the JVM shuts down. I think switching to a fake executor also would fix it.
romtsn
left a comment
There was a problem hiding this comment.
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.
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 <noreply@anthropic.com>

DefaultCompositePerformanceCollectorsampled CPU and memory on ajava.util.Timer, which uses the wall clock, so sampling stopped after a backward clock step. It now runs onoptions.getTimerExecutorService(), which usesSystem.nanoTime(). Each run schedules the next one 100ms later, the same fixed delay as before.Worth reviewing:
generationkeeps a run that is already executing from rescheduling afterclose(). The run can trigger thatclose()itself by timing out the last transaction.setup()andcollect()back to back, givingAndroidCpuCollectora near-zero interval.The 30s timeout still uses the wall clock. #6101 fixes it on
9.x.x, so expect a small conflict there. Based on #5816, which was closed without review.#skip-changelog
🤖 Generated with Claude Code