Skip to content

Commit

Permalink
changed jitter
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Oct 19, 2023
1 parent 66fe71c commit e3f6fb5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/connection/connection_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ function createParameters()
},
{
name: PARAM_RETRY_SF_MAX_SLEEP_TIME,
defaultValue: 300,
defaultValue: 16,
validate: isNonNegativeNumber
}
];
Expand Down
5 changes: 3 additions & 2 deletions lib/services/sf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

}

Expand All @@ -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;
}
/**
Expand Down

0 comments on commit e3f6fb5

Please sign in to comment.