diff --git a/lib/connection/connection_config.js b/lib/connection/connection_config.js index ceef29f12..4b37a62b9 100644 --- a/lib/connection/connection_config.js +++ b/lib/connection/connection_config.js @@ -964,7 +964,7 @@ function createParameters() }, { name: PARAM_RETRY_SF_MAX_SLEEP_TIME, - defaultValue: 300, + defaultValue: 16, validate: isNonNegativeNumber } ]; diff --git a/lib/services/sf.js b/lib/services/sf.js index c106f598f..1c89a5d74 100644 --- a/lib/services/sf.js +++ b/lib/services/sf.js @@ -1207,8 +1207,9 @@ StateConnecting.prototype.continue = function () isRetryableNetworkError(err) || isRetryableHttpError(err))) { numRetries++; - sleep = Util.nextSleepTime(1, cap, sleep); - // sleep = Util.jitteredSleepTime(numRetries, cap); + // sleep = Util.nextSleepTime(1, cap, sleep); + sleep = Util.jitteredSleepTime(numRetries, sleep, cap); + console.log(sleep); setTimeout(sendRequest, sleep * 1000); return; } diff --git a/lib/util.js b/lib/util.js index 5dab8aefd..52dc92cd6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -406,6 +406,7 @@ exports.isNode = function () * Returns the next sleep time calculated by exponential backoff with * decorrelated jitter. * sleep = min(cap, random_between(base, sleep * 3)) + * * for more details, check out: * http://www.awsarchitectureblog.com/2015/03/backoff.html * @param base minimum seconds @@ -420,9 +421,9 @@ exports.nextSleepTime = function ( Math.min(base, previousSleep * 3)); }; -exports.jitteredSleepTime = function (numofRetries,maxSleepTime) { - const temp = Math.min(maxSleepTime, 2** numofRetries); - return temp / 2 + getJitter(temp); +exports.jitteredSleepTime = function (numofRetries, currentSleepTime, maxSleepTime) { + const nextSleepTime = Math.min(maxSleepTime, 2 ** numofRetries); + return nextSleepTime + getJitter(currentSleepTime); } @@ -433,7 +434,7 @@ function getJitter (curWaitTime) { } function chooseRandom (firstNumber, secondNumber) { - const random = Math.floor(Math.random()); + const random = Math.floor(Math.random()*1000); return random % 2 === 0 ? firstNumber : secondNumber; } /**