Error retries and index AWS in retreat Error Retries and Exponential Backoff

A large number of components on the network (such as DNS servers, switches, load balancers, etc.) may request the life cycle of any link problems in a given. In a networked environment, conventional processing techniques to respond to these errors is to implement retry the client application. This technology can improve application reliability and lower operating costs developers.

Each AWS SDK will automatically retry logic. AWS SDK for Java will automatically retry the request, you can use the  ClientConfiguration class to configure the retry settings. For example, for requests made using lowest latency and do not want to retry the page, you might want to turn off retry logic. You can use the  ClientConfiguration class, and to  maxErrorRetry provide  0 this value, which is set to not try again.

If you do not use the AWS SDK, you shall receive server error (5xx) or limit error retry the original request. However, the client error (4xx) you need to modify the request itself, correct the problem, and then try again.

In addition to simply try again, each AWS development kit further embodiment exponential backoff algorithm to achieve better process control. Exponential backoff principle is the wrong response to continuous retry interval to wait longer and longer. You should implement the longest delay interval and the maximum number of retries. Maximum delay interval and the maximum number of retries is not necessarily a fixed value, and should be set according to the operation being performed and other local factors (e.g., network delay).

Most exponential backoff algorithm will use jitter (random delay) to prevent continuous conflict. Because in these cases you do not try to avoid such a conflict, there is no need to use this random number. However, if concurrent clients, shake to help you succeed faster execution of the request.

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 = 0;
        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(2, retryCount) * 100L);

    return waitTime;
}

 

Guess you like

Origin www.cnblogs.com/cloudrivers/p/11620469.html