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 exponential and server-mediated backoff on retries #56

Closed
wants to merge 1 commit into from

Conversation

nolanmar511
Copy link
Contributor

@nolanmar511 nolanmar511 commented Nov 16, 2017

Fixes #43 and #44

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 16, 2017
@codecov
Copy link

codecov bot commented Nov 16, 2017

Codecov Report

Merging #56 into master will increase coverage by 3.97%.
The diff coverage is 97.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #56      +/-   ##
==========================================
+ Coverage   92.95%   96.92%   +3.97%     
==========================================
  Files           6        6              
  Lines         298      325      +27     
  Branches       54       59       +5     
==========================================
+ Hits          277      315      +38     
+ Misses         21       10      -11
Impacted Files Coverage Δ
ts/src/config.ts 100% <100%> (ø) ⬆️
ts/src/profiler.ts 96.07% <97.61%> (+9.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8fe22e2...5c79415. Read the comment docs.

ts/src/config.ts Outdated
// by the server response, then profiler will wait this long before asking
// server to create a profile again. After a successful profile creation,
// the backoff will be reset to initialExpBackoffMillis.
initialExpBackoffMillis?: number;

This comment was marked as spam.

This comment was marked as spam.

ts/src/config.ts Outdated
@@ -108,5 +125,8 @@ export const defaultConfig = {
timeIntervalMicros: 1000,
heapIntervalBytes: 512 * 1024,
heapMaxStackDepth: 64,
backoffMillis: 5 * 60 * 1000
initialExpBackoffMillis: 1000,
maxExpBackoffMillis: 60 * 60 * 1000,

This comment was marked as spam.

This comment was marked as spam.

ts/src/config.ts Outdated
initialExpBackoffMillis: 1000,
maxExpBackoffMillis: 60 * 60 * 1000,
expBackoffMultiplier: 1.3,
backoffLimitMillis: 7 * 24 * 60 * 60 * 1000, // 7 days

This comment was marked as spam.

This comment was marked as spam.

super(message.toString());
this.statusCode = response.statusCode;
if (isServerBackoffResponse(response)) {
this.backoffMillis = parseDuration(response.body.details.retryDelay);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}
getBackoff(): number {
const curBackoff = this.nextBackoff;
this.nextBackoff = this.backoffMultiplier * this.nextBackoff;

This comment was marked as spam.

This comment was marked as spam.

@@ -201,29 +254,37 @@ export class Profiler extends common.ServiceObject {
const delayMillis = await this.collectProfile();

// Schedule the next profile.
setTimeout(this.runLoop.bind(this), delayMillis).unref();
if (typeof delayMillis === 'number') {

This comment was marked as spam.

This comment was marked as spam.

@@ -126,6 +137,48 @@ async function profileBytes(p: perftools.profiles.IProfile): Promise<string> {
}

/**
* Error which also indicates how long backoff should be in response to the

This comment was marked as spam.

This comment was marked as spam.

backoffMillis?: number;
statusCode: number;
constructor(response: http.ServerResponse) {
let message: number|string = response.statusCode;

This comment was marked as spam.

This comment was marked as spam.

*/
async collectProfile(): Promise<number> {
async collectProfile(retryer?: Retryer): Promise<number|Retryer> {

This comment was marked as spam.

This comment was marked as spam.

let prof: RequestProfile;
try {
prof = await this.createProfile();
} catch (err) {
this.logger.error(
`Error requesting profile type to be collected: ${err}.`);
return this.config.backoffMillis;
if (err.backoffMillis !== undefined) {

This comment was marked as spam.

This comment was marked as spam.

throw new Error(`Profile not valid: ${body}.`);
}
return body;
return await new Promise<RequestProfile>((resolve, reject) => {

This comment was marked as spam.

This comment was marked as spam.

*/
class BackoffResponseError extends Error {
// tslint:disable-next-line: variable-name
__proto__: Error;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

export class Retryer {
private nextMaxBackoffMillis: number;
constructor(
private initialBackoffMillis: number, private maxBackoffMillis: number,

This comment was marked as spam.

This comment was marked as spam.

initialBackoffMillis: 1000,
maxBackoffMillis: 60 * 60 * 1000,
backoffMultiplier: 1.3,
backoffLimitMillis: 7 * 24 * 60 * 60 * 1000

This comment was marked as spam.

This comment was marked as spam.

const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
assert.equal(7 * 24 * 60 * 60 * 1000, delayMillis);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Nov 20, 2017
@ofrobots
Copy link
Contributor

@nolanmar511, I am not sure why the bot is unhappy. Did you use a different computer, or edit your git config perhaps?

@nolanmar511
Copy link
Contributor Author

I'm pretty sure the bot is unhappy after I merged.
Some of the commits are commits that were merged in.

@nolanmar511
Copy link
Contributor Author

With the changes from #60 merged in, tests here started to fail and I couldn't figure out why. I filed #68 with more details on this.
This PR reverts #60.

@aalexand
Copy link
Contributor

aalexand commented Nov 20, 2017 via email

@aalexand
Copy link
Contributor

aalexand commented Nov 20, 2017 via email

@nolanmar511
Copy link
Contributor Author

PTAL

@nolanmar511 nolanmar511 force-pushed the retry-request branch 2 times, most recently from 69ebe62 to 5ea0f63 Compare November 21, 2017 21:18
@nolanmar511
Copy link
Contributor Author

Closed, because I could not get the CLA approval again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: no This human has *not* signed the Contributor License Agreement. in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants