Skip to content

Commit bdc472a

Browse files
committed
Add default retry params that align with SLA (#860)
* Add default retry params that align with SLA * modify default retry params to conform with datastore, storage, and bigquery sla * Javadoc adjustments
1 parent a8ec412 commit bdc472a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ public final class RetryParams implements Serializable {
4848

4949
private static final long serialVersionUID = -8492751576749007700L;
5050

51+
/**
52+
* Note that App Engine Standard Environment front-end modules have a 60 second deadline for HTTP
53+
* requests. For that reason, we set the default total retry period to less than 60 seconds.
54+
*/
55+
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;
5156
public static final int DEFAULT_RETRY_MIN_ATTEMPTS = 3;
5257
public static final int DEFAULT_RETRY_MAX_ATTEMPTS = 6;
53-
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 250L;
54-
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 10_000L;
58+
public static final long DEFAULT_INITIAL_RETRY_DELAY_MILLIS = 1000L;
59+
public static final long DEFAULT_MAX_RETRY_DELAY_MILLIS = 32_000L;
5560
public static final double DEFAULT_RETRY_DELAY_BACKOFF_FACTOR = 2.0;
56-
public static final long DEFAULT_TOTAL_RETRY_PERIOD_MILLIS = 50_000L;
5761

5862
private final int retryMinAttempts;
5963
private final int retryMaxAttempts;
@@ -62,6 +66,9 @@ public final class RetryParams implements Serializable {
6266
private final double retryDelayBackoffFactor;
6367
private final long totalRetryPeriodMillis;
6468

69+
// Some services may have different backoff requirements listed in their SLAs. Be sure to override
70+
// ServiceOptions.defaultRetryParams() in options subclasses when the service's backoff
71+
// requirement differs from the default parameters used here.
6572
private static final RetryParams DEFAULT_INSTANCE = new RetryParams(new Builder());
6673
private static final RetryParams NO_RETRIES =
6774
builder().retryMaxAttempts(1).retryMinAttempts(1).build();
@@ -156,7 +163,9 @@ public Builder retryDelayBackoffFactor(double retryDelayBackoffFactor) {
156163
}
157164

158165
/**
159-
* Sets totalRetryPeriodMillis.
166+
* Sets totalRetryPeriodMillis. Note that App Engine Standard Environment front-end modules have
167+
* a 60 second deadline for HTTP requests. For that reason, you should set the total retry
168+
* period to under 60 seconds if you are using it on an App Engine front-end module.
160169
*
161170
* @param totalRetryPeriodMillis the totalRetryPeriodMillis to set
162171
* @return the Builder for chaining
@@ -295,4 +304,8 @@ public String toString() {
295304
public static Builder builder() {
296305
return new Builder();
297306
}
307+
308+
public Builder toBuilder() {
309+
return new Builder(this);
310+
}
298311
}

gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
333333
authCredentials =
334334
builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials();
335335
authCredentialsState = authCredentials != null ? authCredentials.capture() : null;
336-
retryParams = firstNonNull(builder.retryParams, RetryParams.defaultInstance());
336+
retryParams = firstNonNull(builder.retryParams, defaultRetryParams());
337337
serviceFactory = firstNonNull(builder.serviceFactory,
338338
getFromServiceLoader(serviceFactoryClass, defaultServiceFactory()));
339339
serviceFactoryClassName = serviceFactory.getClass().getName();
@@ -654,6 +654,15 @@ private static <T> T newInstance(String className) throws IOException, ClassNotF
654654

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

657+
/**
658+
* Some services may have different backoff requirements listed in their SLAs. Be sure to override
659+
* this method in options subclasses when the service's backoff requirement differs from the
660+
* default parameters listed in {@link RetryParams}.
661+
*/
662+
protected RetryParams defaultRetryParams() {
663+
return RetryParams.defaultInstance();
664+
}
665+
657666
private static <T> T getFromServiceLoader(Class<? extends T> clazz, T defaultInstance) {
658667
return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance);
659668
}

0 commit comments

Comments
 (0)