Skip to content

Instantly share code, notes, and snippets.

@tq-jappy
Created March 14, 2021 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tq-jappy/f48595e07374aea672aaed94233e6d61 to your computer and use it in GitHub Desktop.
Save tq-jappy/f48595e07374aea672aaed94233e6d61 to your computer and use it in GitHub Desktop.
package sample;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.retry.PredefinedRetryPolicies;
import com.amazonaws.retry.RetryPolicy;
import com.amazonaws.services.dynamodbv2.model.InternalServerErrorException;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughputExceededException;
public class AwsSdkBackoffSimulation {
public static void main(String[] args) {
RetryPolicy.BackoffStrategy backoffStrategy1 = new ClientConfiguration()
.getRetryPolicy()
.getBackoffStrategy();
RetryPolicy.BackoffStrategy backoffStrategy2 = new ClientConfiguration()
.withRetryPolicy(PredefinedRetryPolicies.DYNAMODB_DEFAULT)
.getRetryPolicy()
.getBackoffStrategy();
AmazonClientException error = new InternalServerErrorException("error");
ProvisionedThroughputExceededException throttleError = new ProvisionedThroughputExceededException("error");
throttleError.setErrorCode("ThrottlingException");
for (int i = 0; i < 10; i++) {
System.out.println(String.format("%03d, DEFAULT: %6d, DYNAMODB_DEFAULT: %6d, DEFAULT(throttleError): %6d, DYNAMODB_DEFAULT(throttleError): %6d",
i,
backoffStrategy1.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, error, i),
backoffStrategy2.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, error, i),
backoffStrategy1.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, throttleError, i),
backoffStrategy2.delayBeforeNextRetry(AmazonWebServiceRequest.NOOP, throttleError, i)));
}
}
}
@tq-jappy
Copy link
Author

サンプル実行結果

000, DEFAULT:     56, DYNAMODB_DEFAULT:      5, DEFAULT(throttleError):    472, DYNAMODB_DEFAULT(throttleError):    420
001, DEFAULT:    152, DYNAMODB_DEFAULT:      3, DEFAULT(throttleError):    710, DYNAMODB_DEFAULT(throttleError):    657
002, DEFAULT:    345, DYNAMODB_DEFAULT:     27, DEFAULT(throttleError):   1748, DYNAMODB_DEFAULT(throttleError):   1553
003, DEFAULT:      6, DYNAMODB_DEFAULT:    104, DEFAULT(throttleError):   2544, DYNAMODB_DEFAULT(throttleError):   3162
004, DEFAULT:    813, DYNAMODB_DEFAULT:     28, DEFAULT(throttleError):   7258, DYNAMODB_DEFAULT(throttleError):   4162
005, DEFAULT:   1279, DYNAMODB_DEFAULT:    798, DEFAULT(throttleError):  13568, DYNAMODB_DEFAULT(throttleError):  10524
006, DEFAULT:   1308, DYNAMODB_DEFAULT:    565, DEFAULT(throttleError):  12845, DYNAMODB_DEFAULT(throttleError):  16461
007, DEFAULT:   3089, DYNAMODB_DEFAULT:   2425, DEFAULT(throttleError):  17140, DYNAMODB_DEFAULT(throttleError):  12536
008, DEFAULT:   1517, DYNAMODB_DEFAULT:   4147, DEFAULT(throttleError):  17606, DYNAMODB_DEFAULT(throttleError):  13507
009, DEFAULT:  17415, DYNAMODB_DEFAULT:   3009, DEFAULT(throttleError):  10704, DYNAMODB_DEFAULT(throttleError):  13932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment