Repository navigation
Delay every data update poll by a random amount, drawn afresh each time - #182
Draft
jwrosewell wants to merge 3 commits into
Draft
jwrosewell wants to merge 3 commits into
jwrosewell wants to merge 3 commits into
Conversation
The delay hashed the time elapsed since an instant made a moment before, which is close to zero on every call, with the thread's id, so every process drew from a handful of values and instances started together polled together. Polls after the first added no delay at all. The delay is now drawn from a randomly keyed hasher and added to every poll, as the specification says.
This was referenced Oct 27, 2026
Draft
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.
Closes #161.
Problem
randomisationhashedInstant::now().elapsed(), the time since an instant made a moment before, with the thread's id, throughDefaultHasher, whose keys are fixed (pipeline-engines/src/data_update_service.rslines 295 to 307). The elapsed time is a few nanoseconds on every call, so every process drew from the same few values, and 200 draws of a delay of up to 600 seconds gave two different values.run_due_pollsscheduled every poll after the first at the polling interval alone (lines 512 to 527). Instances started together therefore polled the Distributor together, every time. The specification adds a random time to every interval (data-updates.md lines 354 to 356), as .NET and Java do. #161 has the details.Change
RandomState, whose keys the standard library draws from the operating system, and seeded with the system time, so it differs between calls and between processes without a random number generator dependency.poll_intervalandrandomisationtake no service, so the scheduler can call them.How it was verified
New unit tests in
pipeline-engines/src/data_update_service.rs:the_first_poll_is_delayed_at_randomdraws 200 delays of up to 600 seconds and checks more than 100 differ. About 170 differ when the draws are random.each_later_poll_adds_a_random_delayruns five due polls with a 1,000 second interval and a 1,000 second maximum delay, and checks at least one is next due more than a second after the interval. All five would land under two seconds once in about 3 * 10^13 runs.Before the change, on a branch holding only the new tests, both fail,
the_first_poll_is_delayed_at_randomwith2 different delays in 200: {114, 592}andeach_later_poll_adds_a_random_delaywithno poll after the first added a delay. After it, both pass, and the first prints180 different delays in 200.Locally on Windows, with all seven fixes of this sweep merged together (#175, #178, #182, #184, #194, #195 and #196),
cargo test --no-fail-fast -p fiftyone-pipeline-engines -p fiftyone-device-detection-onpremise -p fiftyone-ip-intelligence-onpremise -p fiftyone-device-detection -p fiftyone-ip-intelligence -- --nocapture, with51DEGREES_DD_PATHnaming the Lite Hash file,Enterprise-HashV41.hashbeside it, and51DEGREES_IPI_PATHnaming the ASN file,51Degrees-LiteV41.ipibeside it, gives 130 passed, 0 failed and 2 ignored across 24 test binaries. With the fixes merged,cargo doc --workspace --no-depswithRUSTDOCFLAGS="-D warnings"passes, andrustfmt --checkpasses on every file the seven fixes change.cargo clippy --workspace --all-targets -- -D warningson the merged fixes has not run yet. ThePull Requestworkflow, which builds and tests each pull request on every platform, is waiting for approval to run.Behaviour that changes
Polls are spread across the configured maximum randomisation, the first and every later one, so instances started together drift apart. A poll after the first now comes between the polling interval and the polling interval plus the maximum randomisation after the one before, where before it came after the polling interval exactly.
What remains
Nothing in this change.