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

Add default retry params that align with SLA #860

Merged
merged 3 commits into from Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java
Expand Up @@ -48,12 +48,16 @@ public final class RetryParams implements Serializable {

private static final long serialVersionUID = -8492751576749007700L;

/**
* Note that App Engine Standard Environment front-end modules have a 60 second deadline for HTTP
* requests. For that reason, we set the default total retry period to less than 60 seconds.
*/
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;

This comment was marked as spam.

This comment was marked as spam.

public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3;
public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6;
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 250L;
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 10_000L;
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 1000L;
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 32_000L;
public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0;
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;

private final int retryMinAttempts;
private final int retryMaxAttempts;
Expand All @@ -62,6 +66,9 @@ public final class RetryParams implements Serializable {
private final double retryDelayBackoffFactor;
private final long totalRetryPeriodMillis;

// Some services may have different backoff requirements listed in their SLAs. Be sure to override

This comment was marked as spam.

// ServiceOptions.defaultRetryParams() in options subclasses when the service's backoff
// requirement differs from the default parameters used here.
private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder());
private static final RetryParams NO_RETRIES =
builder().retryMaxAttempts(1).retryMinAttempts(1).build();
Expand Down Expand Up @@ -156,7 +163,9 @@ public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) {
}

/**
* Sets totalRetryPeriodMillis.
* Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have
* a 60 second deadline for HTTP requests. For that reason, you should set the total retry
* period to under 60 seconds if you are using it on an App Engine front-end module.
*
* @param totalRetryPeriodMillis the totalRetryPeriodMillis to set
* @return the Builder for chaining
Expand Down Expand Up @@ -295,4 +304,8 @@ public String toString() {
public static Builder builder() {
return new Builder();
}

public Builder toBuilder() {
return new Builder(this);
}
}
Expand Up @@ -333,7 +333,7 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
authCredentials =
builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials();
authCredentialsState = authCredentials != null ? authCredentials.capture() : null;
retryParams = firstNonNull(builder.retryParams, RetryParams.defaultInstance());
retryParams = firstNonNull(builder.retryParams, defaultRetryParams());
serviceFactory = firstNonNull(builder.serviceFactory,
getFromServiceLoader(serviceFactoryClass, defaultServiceFactory()));
serviceFactoryClassName = serviceFactory.getClass().getName();
Expand Down Expand Up @@ -655,6 +655,15 @@ private static <T> T newInstance(String className) throws IOException, ClassNotF

public abstract <B extends Builder<ServiceT, ServiceRpcT, OptionsT, B>> B toBuilder();

/**
* Some services may have different backoff requirements listed in their SLAs. Be sure to override
* this method in options subclasses when the service's backoff requirement differs from the
* default parameters listed in {@link RetryParams}.
*/
protected RetryParams defaultRetryParams() {
return RetryParams.defaultInstance();
}

private static <T> T getFromServiceLoader(Class<? extends T> clazz, T defaultInstance) {
return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance);
}
Expand Down