Skip to content
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

[RRIO] [Call] Create CallShouldBackoff and default implementation #28952

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update javadoc
  • Loading branch information
damondouglas committed Oct 16, 2023
commit f825c829cc79b2ec7977397b73bdad3309029ee4
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,40 @@
class CallShouldBackoffBasedOnRejectionProbability<ResponseT>
implements CallShouldBackoff<ResponseT> {

// Default value recommended by https://sre.google/sre-book/handling-overload/
// Default multiplier value recommended by https://sre.google/sre-book/handling-overload/
private static final double DEFAULT_MULTIPLIER = 2.0;

// The threshold is the value that pReject() must exceed in order to report a value() of true. If
// null, then the computation relies on a random value.
private @Nullable Double threshold;

// The multiplier drives the impact of accepts on the rejection probability. See <a
// https://sre.google/sre-book/handling-overload/ for details.
private final double multiplier;

// The number of total requests called to a remote API.
private double requests = 0;

// The number of total accepts called to a remote API.
private double accepts = 0;

/** Instantiate class with the {@link #DEFAULT_MULTIPLIER}. */
CallShouldBackoffBasedOnRejectionProbability() {
damondouglas marked this conversation as resolved.
Show resolved Hide resolved
this(DEFAULT_MULTIPLIER);
}

/**
* Instantiates class with the provided multiplier. The multiplier drives the impact of accepts on
* the rejection probability. See https://sre.google/sre-book/handling-overload/ for details.
*/
CallShouldBackoffBasedOnRejectionProbability(double multiplier) {
this.multiplier = multiplier;
}

private @Nullable Double threshold;
private final double multiplier;
private double requests = 0;
private double accepts = 0;

/**
* Setter for the threshold that overrides usage of a random value. The threshold is the value
* that pReject() must exceed in order to report a value() of true.
damondouglas marked this conversation as resolved.
Show resolved Hide resolved
damondouglas marked this conversation as resolved.
Show resolved Hide resolved
*/
CallShouldBackoffBasedOnRejectionProbability<ResponseT> setThreshold(double threshold) {
this.threshold = threshold;
return this;
Expand Down
Loading