dataconnect(feat): add "jitter" to exponential backoff logic when reconnecting realtime streaming connections#8456
dataconnect(feat): add "jitter" to exponential backoff logic when reconnecting realtime streaming connections#8456dconeybe wants to merge 7 commits into
Conversation
…aConnectBidiConnectStream
…instead of defaulting to no jitter
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the backoff calculation mechanism in Firebase Data Connect to support customizable random jitter. The RetryBackoffCalculator now requires a jitter generator function, and a Random instance is passed down from the registrar through the factory, implementation, and gRPC classes to the stream. Unit tests have been updated and expanded with a new helper file RetryBackoffCalculatorTesting.kt to verify exponential backoff behavior under various jitter conditions. No review comments were provided, so there is no additional feedback.
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
This PR integrates random jitter into the exponential backoff strategy used by
firebase-dataconnectwhen reconnecting query subscriptions. This is achieved by wiring aRandominstance fromFirebaseDataConnectRegistrarthrough toDataConnectBidiConnectStreamto introduce random jitter between -0.5 and 0.5 to the exponential backoff calculation. This helps reduce thundering herd problems on reconnects.Highlights
DataConnectBidiConnectStreamto use a random jitter factor (varying between -0.5 and 0.5) withRetryBackoffCalculatorfor reconnecting query subscriptions.Randominstance fromFirebaseDataConnectRegistrardown throughFirebaseDataConnectFactory,FirebaseDataConnectImpl, andDataConnectGrpcRPCstoDataConnectBidiConnectStream.QuerySubscriptionImplUnitTestto cover zero, minimum, maximum, and varying jitter using property-based tests.RetryBackoffCalculatorTestingto share common backoff test constants and generators, reducing duplication across test files.Changelog
Randomparameter to the constructor and initializedRetryBackoffCalculatorwith a lambda generating jitter between -0.5 and 0.5.random: Randomconstructor parameter and passed it when instantiatingDataConnectBidiConnectStream.random: Randomconstructor parameter, used it to initializeidStringGenerator, and passed it toFirebaseDataConnectImpl.random: Randomconstructor parameter and passed it toDataConnectGrpcRPCs.Random.DefaulttoFirebaseDataConnectFactory.getRandomJitterconstructor parameter to require caller-specified jitter strategy.Random.Default.Random.Default.Randomand verify that connection retry wait times match expected exponential backoff with zero, min, max, or varying jitter.backoffValues,minJitterBackoffValues,maxJitterBackoffValues) and anArbgenerator for jitter test cases.RetryBackoffCalculatorTestingand updated calculator instantiation to provide explicit jitter lambdas.