@Override public int getSleepTimeMs(int retryCount, long elapsedTimeMs) { if (retryCount < expRetriesThreshold) { int exp = 1 << retryCount; int jitter = random.nextInt(exp); return super.getBaseSleepTimeMs() + exp + jitter; } else { int stepJitter = random.nextInt(stepSize); return Math.min(super.getMaxSleepTimeMs(), (linearBaseSleepMs + (stepSize * (retryCount - expRetriesThreshold)) + stepJitter)); } } }
/** * The class provides generic exponential-linear backoff retry strategy for storm. It calculates threshold for exponentially increasing sleeptime for * retries. Beyond this threshold, the sleeptime increase is linear. Also adds jitter for exponential/linear retry. It guarantees currSleepTimeMs >= * prevSleepTimeMs and baseSleepTimeMs <= currSleepTimeMs <= maxSleepTimeMs */ public StormBoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries) { super(baseSleepTimeMs, maxSleepTimeMs, maxRetries); expRetriesThreshold = 1; while ((1 << (expRetriesThreshold + 1)) < ((maxSleepTimeMs - baseSleepTimeMs) / 2)) expRetriesThreshold++; LOG.info("The baseSleepTimeMs [" + baseSleepTimeMs + "] the maxSleepTimeMs [" + maxSleepTimeMs + "] " + "the maxRetries [" + maxRetries + "]"); if (baseSleepTimeMs > maxSleepTimeMs) { LOG.warn("Misconfiguration: the baseSleepTimeMs [" + baseSleepTimeMs + "] can't be greater than " + "the maxSleepTimeMs [" + maxSleepTimeMs + "]."); } if (maxRetries > 0 && maxRetries > expRetriesThreshold) { this.stepSize = Math.max(1, (maxSleepTimeMs - (1 << expRetriesThreshold)) / (maxRetries - expRetriesThreshold)); } else { this.stepSize = 1; } this.linearBaseSleepMs = super.getBaseSleepTimeMs() + (1 << expRetriesThreshold); }
public LeafBoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries) { super(baseSleepTimeMs, maxSleepTimeMs, maxRetries); expRetriesThreshold = 1; while ( (1 << (expRetriesThreshold + 1)) < ((maxSleepTimeMs - baseSleepTimeMs) /2 )) { expRetriesThreshold ++ ; } LOG.info("The baseSleepTimeMs [" + baseSleepTimeMs + "] the maxSleepTimeMs [" + maxSleepTimeMs +"]" + "the maxRetries [" + maxRetries +"]" ); if (baseSleepTimeMs > maxSleepTimeMs) { LOG.warn("Misconfiguration: the baseSleepTimeMs [" + baseSleepTimeMs +"] can not be greater than the maxSleepTimeMs [" + maxSleepTimeMs +"]"); if (maxRetries > 0 && maxRetries > expRetriesThreshold) { this.stepSize = Math.max(1 ,(maxSleepTimeMs - (1 << expRetriesThreshold))/ (maxRetries - expRetriesThreshold)); } else { this.stepSize = 1; } } this.linearBaseSleepMs = super.getBaseSleepTimeMs() + (1 << expRetriesThreshold); }
@Override protected int getSleepTimeMs(int retryCount, long elapsedTimeMs) { if (retryCount < expRetriesThreshold) { int exp = 1 << retryCount; int jitter = random.nextInt(exp); int sleepTimeMs = super.getBaseSleepTimeMs() + exp + jitter; return sleepTimeMs; } else { int stepJitter = random.nextInt(stepSize); return Math.min(super.getMaxSleepTimeMs(), (linearBaseSleepMs + (stepSize * (retryCount - expRetriesThreshold)) + stepJitter)); } } }