Mark stateless and servo meters when removed - #1293
Merged
brharrington merged 1 commit intoSep 8, 2026
Merged
Conversation
StatelessMeter and the five servo meter types implement RemovableMeter, so SwapMeter.get() gets the flag instead of falling back to hasExpired(). These are the two remaining registries whose expiry check reads the wall clock, so they are the two that were still paying for it on every update after Netflix#1290. Servo has no shared meter base, so the field and the two accessors are repeated per type. Stateless has one, so it is a single place. Not done for the other registries, because there is nothing to gain: SidecarMeter, the metrics3 and metrics5 meters and the DefaultRegistry types all return a constant false from hasExpired(), so the fallback costs them nothing beyond the type test. Adopting the flag there would change behaviour rather than cost, by letting a held reference recover after a removal it currently never notices, and that is worth doing on its own terms rather than as part of this.
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.
StatelessMeterand the five servo meter types implementRemovableMeter, soSwapMeter.get()reads the flag instead of falling back tohasExpired().These are the two remaining registries whose expiry check reads the wall clock, so they are the two still paying for it on every update after #1290:
hasExpired()now - lastUpdated > ttlclock.wallTime() - lastUpdated > ttlnow - lastUpdated.get() > EXPIRATION_TIME_MILLISreturn falsereturn falseDefaultRegistryreturn falseServo has no shared meter base —
ServoMeteris a functional interface for exposing monitors — so the field and two accessors are repeated acrossServoCounter,ServoTimer,ServoGauge,ServoMaxGaugeandServoDistributionSummary. Stateless has a real base class, so it is one place.Why the other three are left alone
Their
hasExpired()is a constantfalse, so theinstanceoffallback added in #1290 costs them nothing beyond the type test — there is no clock read to remove.The exclusion is not purely about cost, though. Because they are not
RemovableMeter,markRemovedis a no-op for them, soclose()/reset()leaves a held reference bound to an orphan forever. That is unchanged from before this series and is not a regression, but adopting the flag there would be a behaviour improvement rather than a performance one, and belongs on its own terms.Tests
StatelessRemovalMarkingTest(6) andServoRemovalMarkingTest(5), all 11 failing with the production change reverted:close()marking for stateless, which overrides ittheWrapperAddsNoClockReadsOfItsOwnThe servo cleanup test drives
ServoRegistry.getMonitors(), the registry's real cleanup entry point, rather than hand-rolling an iterator loop.On the clock-read test: on servo an absolute count is the wrong assertion, because
ServoCounter.add()reads the clock three times on its own — one perServoPollers.NUM_POLLERSstep bucket inDoubleCounter.increment, pluslastUpdated— and hard-coding that would break on any unrelated change to servo internals. Comparing the wrapper against the meter it delegates to pins the property that matters, that the wrapper adds nothing, and it fails onmainwhere it adds exactly one read. It also asserts the measured floor is non-zero so two zeros cannot satisfy it. On stateless the raw meter reads exactly once, so that side pins the absolute count too.Both registries keep bookkeeping counters of their own in the registry under test (
ValidationHelperis wired tothiswith no way to redirect it), so the tests work from the ids they create rather than from everything the registry holds.