Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add delayFactor param to exponentialDelay #208

Merged
merged 5 commits into from
May 18, 2023

Conversation

dlchen
Copy link
Contributor

@dlchen dlchen commented Jul 28, 2022

Issue

Current implementation of exponentialDelay results in retries based on the order of 100ms – i.e. 100ms, 200ms, 400ms, 800ms, etc. This is in contrast with the Exponential Backoff link found in the README which suggests 1s, 2s, 4s, 8s, etc.

Solution

Add delayFactor param which can be passed 1000. Defaults to 100 as to keep the current behavior.

Related

es/index.mjs Outdated
Comment on lines 77 to 84
export function exponentialDelay(retryNumber = 0) {
const delay = Math.pow(2, retryNumber) * 100;
const delay = Math.pow(2, retryNumber) * 1000;
const randomSum = delay * 0.2 * Math.random(); // 0-20% of the delay
return delay + randomSum;
}
Copy link

@ryparker ryparker Nov 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some updates to satisfy the latest Google recommendations for exponential backoff.

export function exponentialDelay(retryNumber = 0) {
  const randomMs = Math.random() * 1000; // 0 to 1000 milliseconds
  const exponentialDelay = Math.pow(2, retryNumber) * 1000 + randomMs;
  const maxBackoff = 64 * 1000; // 64 seconds
  const delay = Math.min(exponentialDelay, maxBackoff);
  const deadline = 10 * 60 * 1000; // 10 minutes
  if (delay > deadline) {
    throw new Error(
      `Exponential retry delay exhausted after ${
        deadline / 1000 / 60
      } minutes (${retryNumber} retries).`,
    );
  }
  return delay;
}

We'd probably want to allow the user to configure the maxBackoff and deadline to their liking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea but deserves its own PR IMO.

@mindhells
Copy link
Member

I'd really love if we can make this configurable with a default value equal to the current static value (100)
That way we don't change behavior and we can use a minor version when releasing this changes
WDYT?

@dlchen dlchen changed the title fix: exponentialDelay based on 1000ms not 100ms feat: add delayFactor param to exponentialDelay May 9, 2023
@dlchen
Copy link
Contributor Author

dlchen commented May 9, 2023

I'd really love if we can make this configurable with a default value equal to the current static value (100) That way we don't change behavior and we can use a minor version when releasing this changes WDYT?

@mindhells please review my attempt at this 7845a5a thanks!

@mindhells
Copy link
Member

mindhells commented May 10, 2023

I'd really love if we can make this configurable with a default value equal to the current static value (100) That way we don't change behavior and we can use a minor version when releasing this changes WDYT?

@mindhells please review my attempt at this 7845a5a thanks!

tests got broken, not sure why 🤔 , would you have a look?

* aligns with Google's "Exponential Backoff" link in README
* keep default of 100 to maintain existing behavior
@dlchen
Copy link
Contributor Author

dlchen commented May 12, 2023

I'd really love if we can make this configurable with a default value equal to the current static value (100) That way we don't change behavior and we can use a minor version when releasing this changes WDYT?

@mindhells please review my attempt at this 7845a5a thanks!

tests got broken, not sure why 🤔 , would you have a look?

Looks like error was being passed into the retryDelay function for some reason. I removed it and the tests are passing now.

@mindhells
Copy link
Member

I'd really love if we can make this configurable with a default value equal to the current static value (100) That way we don't change behavior and we can use a minor version when releasing this changes WDYT?

@mindhells please review my attempt at this 7845a5a thanks!

tests got broken, not sure why 🤔 , would you have a look?

Looks like error was being passed into the retryDelay function for some reason. I removed it and the tests are passing now.

Removing the error parameter from the retryDelay callback would break the library API (see Readme)

@dlchen
Copy link
Contributor Author

dlchen commented May 17, 2023

I'd really love if we can make this configurable with a default value equal to the current static value (100) That way we don't change behavior and we can use a minor version when releasing this changes WDYT?

@mindhells please review my attempt at this 7845a5a thanks!

tests got broken, not sure why 🤔 , would you have a look?

Looks like error was being passed into the retryDelay function for some reason. I removed it and the tests are passing now.

Removing the error parameter from the retryDelay callback would break the library API (see Readme)

Gotcha. Well it's kind of awkward since the error is not the first param of the callback. In the name of backwards compatibility this is the best I could come up with. Lmk your thoughts.

@mindhells
Copy link
Member

I'd really love if we can make this configurable with a default value equal to the current static value (100) That way we don't change behavior and we can use a minor version when releasing this changes WDYT?

@mindhells please review my attempt at this 7845a5a thanks!

tests got broken, not sure why 🤔 , would you have a look?

Looks like error was being passed into the retryDelay function for some reason. I removed it and the tests are passing now.

Removing the error parameter from the retryDelay callback would break the library API (see Readme)

Gotcha. Well it's kind of awkward since the error is not the first param of the callback. In the name of backwards compatibility this is the best I could come up with. Lmk your thoughts.

LGTM, thanks a lot!

@mindhells mindhells merged commit 9ae859d into softonic:master May 18, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants