-
Notifications
You must be signed in to change notification settings - Fork 41
Chore: add init exponential backoff + jitter for system_database.go #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: add init exponential backoff + jitter for system_database.go #103
Conversation
Signed-off-by: pranshu-raj-211 <[email protected]>
not returning errors anymore, if retries exceed max retries then return base fixed delay Signed-off-by: pranshu-raj-211 <[email protected]>
use percentage of exp rather than small delay Signed-off-by: pranshu-raj-211 <[email protected]>
dbos/system_database.go
Outdated
| _DB_CONNECTION_RETRY_BASE_DELAY = 500 * time.Millisecond | ||
| _DB_CONNECTION_RETRY_FACTOR = 2 | ||
| _DB_CONNECTION_RETRY_MAX_RETRIES = 3 | ||
| _DB_CONNECTION_MAX_DELAY = 10000 * time.Millisecond | ||
| _DB_RETRY_INTERVAL = 1 * time.Second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can be a bit more lenient on these:
Max delay: 2 minutes
Max retries: 10
Also the base retry delay should be = to the base interval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the base interval do you mean the _DB_RETRY_INTERVAL?
The issue #95 showed the variable that was being used for this, which in the code was _DB_CONNECTION_RETRY_DELAY = 500 * time.Millisecond, which I took as default.
Changed the other values, updating tests to match the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make _DB_CONNECTION_RETRY_BASE_DELAY equal 1 second. Thanks!
make base delay constant 1 second, decrement retryAttempt in notificationListenerLoop, hardcode sleep duration in shutdown, slight change in logic - cap delays to max of 120 seconds, but allow for jitter in that too, add tests according to calculations Signed-off-by: pranshu-raj-211 <[email protected]>
|
Changes done:
Changes that can be done:
|
|
Also, curious about the security action failing, what does it do, gosec job failed at the jitter calculation in my code, just wanted to know. |
|
Ok, the security run fails as gosec wants the use of crypto/rand to replace math/rand. Should I make the changes or is the current version fine(small change)? |
You can disable the warning -- we're not using randomness in a way that needs security here. It can be done with a comment on the line of the warning. See how we do it elsewhere. |
Signed-off-by: pranshu-raj-211 <[email protected]>
|
Added the comment to ignore G404 - rand. |
|
Resolved merge conflicts (resulting from #106 push to main). Tested security and test actions locally (act, using medium size image config). |
|
Also, I was curious, how does this relate to #61 |
its a duplicate. Thanks for your contribution! |
Refer to PR #101 (got closed while renaming branch)
What this PR does
Adds exponential backoff and jitter to replace fixed delays in system_database.go
How it is implemented
Replaced delay interval constant by constants
Func backoffWithJitter takes an argument attempt - attempts of backoff delay done yet.
Calculates the delay as
Capping provided against delay intervals getting too large.
If number of retries exceeds a certain limit - fallback to fixed base delay (500ms)
Jitter added separately even for fixed intervals.
Constants may need to be changed.
Tests
I do have a basic table driven test for this, unsure of which file to add it in.