Error Retries and Exponential Backoff in AWS

https://docs.aws.amazon.com/general/latest/gr/api-retries.html

Numerous components on a network, such as DNS servers, switches, load balancers, and others can generate errors anywhere in the life of a given request. The usual technique for dealing with these error responses in a networked environment is to implement retries in the client application. This technique increases the reliability of the application and reduces operational costs for the developer.

Each AWS SDK implements automatic retry logic. The AWS SDK for Java automatically retries requests, and you can configure the retry settings using the ClientConfiguration class. For example, you might want to turn off the retry logic for a web page that makes a request with minimal latency and no retries. Use theClientConfiguration class and provide a maxErrorRetry value of 0 to turn off the retries.

If you're not using an AWS SDK, you should retry original requests that receive server (5xx) or throttling errors. However, client errors (4xx) indicate that you need to revise the request to correct the problem before trying again.

In addition to simple retries, each AWS SDK implements exponential backoff algorithm for better flow control. The idea behind exponential backoff is to use progressively longer waits between retries for consecutive error responses. You should implement a maximum delay interval, as well as a maximum number of retries. The maximum delay interval and maximum number of retries are not necessarily fixed values, and should be set based on the operation being performed, as well as other local factors, such as network latency.

Most exponential backoff algorithms use jitter (randomized delay) to prevent successive collisions. Because you aren't trying to avoid such collisions in these cases, you don't need to use this random number. However, if you use concurrent clients, jitter can help your requests succeed faster. For more information, see the blog post for Exponential Backoff and Jitter.

The following pseudo code shows one way to poll for a status using an incremental delay.

Do some asynchronous operation.

retries = 

DO
wait for (^retries * ) milliseconds status = Get the result of the asynchronous operation. IF status = SUCCESS
retry = false
ELSE IF status = NOT_READY
retry = true
ELSE IF status = THROTTLED
retry = true
ELSE
Some other error occurred, so stop calling the API.
retry = false
END IF retries = retries + WHILE (retry AND (retries < MAX_RETRIES))

The following code demonstrates how to implement this incremental delay in Java.

 public enum Results {
SUCCESS,
NOT_READY,
THROTTLED,
SERVER_ERROR
} /*
* Performs an asynchronous operation, then polls for the result of the
* operation using an incremental delay.
*/
public static void doOperationAndWaitForResult() { try {
// Do some asynchronous operation.
long token = asyncOperation(); int retries = ;
boolean retry = false; do {
long waitTime = Math.min(getWaitTimeExp(retries), MAX_WAIT_INTERVAL); System.out.print(waitTime + "\n"); // Wait for the result.
Thread.sleep(waitTime); // Get the result of the asynchronous operation.
Results result = getAsyncOperationResult(token); if (Results.SUCCESS == result) {
retry = false;
} else if (Results.NOT_READY == result) {
retry = true;
} else if (Results.THROTTLED == result) {
retry = true;
} else if (Results.SERVER_ERROR == result) {
retry = true;
}
else {
// Some other error occurred, so stop calling the API.
retry = false;
} } while (retry && (retries++ < MAX_RETRIES));
} catch (Exception ex) {
}
} /*
* Returns the next wait interval, in milliseconds, using an exponential
* backoff algorithm.
*/
public static long getWaitTimeExp(int retryCount) { long waitTime = ((long) Math.pow(, retryCount) * 100L); return waitTime;
}

最新文章

  1. 三分钟学会funsioncharts
  2. python 多线程就这么简单
  3. js中创建对象的几种方式
  4. Kernel启动时 驱动是如何加载的module_init,加载的次序如何;略见本文
  5. thinkphp分页显示
  6. 2014-11-26----css的简介
  7. sql 数据库的备份还原问题
  8. Chapter 16_5 单一方法
  9. java中String类型的相关知识
  10. Golang 网络爬虫框架gocolly/colly 四
  11. bzoj1132[POI2008]Tro 计算几何
  12. session.go
  13. [ArcGIS API for JavaScript 4.8] Sample Code-Get Started-popups简介
  14. centos 7.4安装zabbix 3
  15. ansible笔记(5):常用模块之文件操作(二)
  16. mql初学事物和视图
  17. MapReduce编程之wordcount
  18. django之创建第6-1个项目-自定义过滤器
  19. C#使用ActiveMQ实例
  20. hive整合hbase

热门文章

  1. 代码 | 用ALNS框架求解一个TSP问题 - 代码详解
  2. ID生成算法(二)
  3. Tcl循环语句
  4. Centos7使用python3连接inception报错解决办法
  5. Ubuntu 16.04安装完重启后黑屏,光标一直闪
  6. Alpha项目冲刺! Day6-产出
  7. Linux信号使用及自定义信号
  8. Go 语言入门(三)并发
  9. c++ homework 1
  10. 关于Flutter启动项目白屏,报错[ERROR:flutter/shell/gpu/gpu_surface_gl.cc(58)] Failed to setup Skia Gr context.问题的解决方案