HyukjinKwon opened a new pull request, #885:
URL: https://github.com/apache/spark-connect-rust/pull/885

   ### What changes were proposed in this pull request?
   
   PySpark's `RetryPolicyState` adds `random.uniform(0, jitter)` to a wait at 
or above the jitter threshold (`retries.py:166-167`), a draw of Python's 
generator each time. The core's `rand_jitter` seeded one round of xorshift64 
with the nanoseconds of the clock at each call. The top bits of the fraction, 
which make the jitter to the millisecond, depend only on the clock's bits from 
bit 25 up, which change every 33.5 ms. So the retries of calls that fail 
together waited the same jitter. Details are in 
`jira-SPARK-62079-retry-jitter.txt`. Now:
   - **`rand_jitter` takes the next value of the jitter sequence of the 
process.** This is a SplitMix64 sequence whose state advances atomically at 
each call. It is seeded once from the OS's randomness, through uuid's v4, from 
which the client already draws its session and operation IDs. Consecutive 
draws, of one thread or of several, are spread over `[0, max)`. The core takes 
no new dependency.
   - **`test_default_jitter_applies_only_at_or_above_the_threshold`** no longer 
sleeps between its draws. It slept only to change the clock. With the fix, all 
20 of its draws fall below 1 ms with a probability of (1/500)^20, where it 
failed about one time in 2000.
   
   ### Why are the changes needed?
   
   A jitter is there so that the retries of a burst of failing calls, as of the 
clients of a server that restarts, do not reach the server again at once. The 
core's jitter gave them all the same wait within each 33.5 ms window.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The jitters of the retries of the Rust client, and of the Python 
client, whose retries are the core's, are spread over their range, as PySpark's.
   
   ### How was this patch tested?
   
   - **New Rust test**, 
`consecutive_jitters_are_spread_over_the_range_as_the_reference_draws_them`:
     - 200 consecutive draws of `rand_jitter(500)` take at least 100 distinct 
values, about 165 expected, in both halves of the range;
     - 4 threads that draw at once take at least 100 distinct values of 200.
   
     With master's `rand_jitter` it failed in 20 of 20 runs ("1 distinct: [118, 
118, ...]"). With the fix, the jitter tests passed in 50 of 50 runs.
   - **Official suites:** none applies. `test_connect_retry`, the suite of 
PySpark's retry policy, is skipped as a whole file by 
`scripts/dropin_known_failures.txt`, because it tests grpcio's retries of the 
Python client, which the Rust transport replaces. It is skipped on master and 
on this branch alike.
   - **The gates**, on master 6e3a3fc2:
     - `cargo fmt --all --check`;
     - `cargo +1.100.0 clippy -p apache-spark-connect-core -p 
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
     - `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps` of the four crates, 
also `--features apache-spark-connect/wasm-udf`;
     - in debug, as the coverage job builds them:
       - all of `cargo test -p apache-spark-connect-core`: lib 259, 
`server_session` 12, `reattach_cleanup` 19, `proxy` 20, `deadlines` 17, 
`artifact_uploads` 7, `user_context` 4 passed (`integration_test` 3 ignored);
       - `cargo test -p apache-spark-connect --lib`: 815 passed;
     - `cargo test -p pyspark-rs --lib`: 15 passed;
     - the coverage step of `coverage.yml`, with its commands and its 
`.coveragerc`: 6572 passed, 79 skipped, 93.42% (floor 93.00%);
     - `test_dropin_e2e.py -k "retry or reattach or interrupt"` against a Spark 
4.3.0 server: 4 passed.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to