Port akka-core#31834: Add ScheduledClock to reduce nanoTime overhead in recency-based passivation#2766
Merged
pjfanning merged 3 commits intoapache:mainfrom Mar 22, 2026
Conversation
…ation strategies Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com> Agent-Logs-Url: https://github.com/pjfanning/incubator-pekko/sessions/76266e9b-5d21-4c79-976f-82c1cc8b6f54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
part of #2730
Recency-based passivation strategies (the new default) call
System.nanoTime()on every message. This introduces aScheduledClockthat refreshes the timestamp on a configurable interval (default 1s) and increments a counter between updates — eliminating per-messagenanoTimecalls under high throughput.New:
Clockactor extension (org.apache.pekko.util)Clock—Extensiontrait withcurrentTime(): LongandearlierTime(duration): LongNanoClock— directSystem.nanoTime()delegate (used whenscheduled-clock-interval = 0)ScheduledClock— updates via scheduler at the configured interval; increments atomically between updates so time never goes backwardsConfig
Internal API changes
RecencyList— removed innerClock/NanoClock; addedapply(clock: Clock)factoryFrequencyList.withOverallRecency.emptyandSegmentedRecencyList.withOverallRecency.empty— now take an explicitClockparameter instead of constructing aNanoClockinternallyEntityPassivationStrategy.apply— signature changed to acceptclock: () => Clock; all strategy and replacement-policy constructors propagate the clockShard— passes() => Clock(context.system)toEntityPassivationStrategySimulator— updated to pass clock factory through to all strategy creatorsTests
TestClock— shared controlled clock extracted from per-spec companion objectsScheduledClockSpec— covers scheduled update, per-call increment, and non-regression (time never decreases under concurrent access)System.nanoTime()withclock.currentTime()for consistency; test config setspekko.scheduled-clock-interval = 100 ms