Allow an explicit now in the ETS fix_window backend#187
Open
neilberkman wants to merge 1 commit into
Open
Conversation
The fix_window algorithm reads the current time from Hammer.ETS.now/0, so a caller cannot pin the window. Tests that exercise window boundaries have to sleep across a real wall-clock boundary, and downstreams that want a custom clock have no seam. Add an optional trailing now argument (timestamp in the backend's time unit) to FixWindow.hit/inc/get, defaulting to ETS.now/0 so existing callers are unaffected, and generate the matching arity in the use Hammer wrappers when the algorithm supports it. Windows become deterministic without sleeping.
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.
Motivation
The
:fix_windowETS backend computes its window fromHammer.ETS.now/0(System.system_time(:millisecond)), so there is no way for a caller to pin the current time. Two consequences::timer.sleep/1across a real wall-clock boundary (seetest/hammer/ets/fix_window_test.exs"returns expected tuples after waiting for the next window"), which is slow and can flake.What this does
Adds an optional trailing
nowargument (a timestamp in the backend's time unit) toHammer.ETS.FixWindow.hit/inc/get, defaulting toETS.now/0, and generates the matching arity in theuse Hammerwrappers when the algorithm exports it:nowdefaults toETS.now/0, so every existing call site and the existing generated arities are untouched.function_exported?(@algorithm, :hit, 6)etc., so only algorithms that opt in get it.get/4) without sleeping.mix testandmix format --check-formattedare green.Open question
I scoped this to
:fix_window(the default and most common) to keep the change small. Happy to extend the same optional-nowseam to:fix_window_per_key/:sliding_window(and the Atomic backends) in this PR or a follow-up if you'd prefer it applied consistently across algorithms - let me know which you'd rather review.