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

Feature: make retry strategy exponential backoff multiplier configurable #1548

Merged
merged 8 commits into from
Jul 15, 2022

Conversation

Velfi
Copy link
Contributor

@Velfi Velfi commented Jul 12, 2022

NOTE: I plan to allow for user-defined retry strategies in a separate PR.

Motivation and Context

aws-sdk-rust#567

Description

Updated SDK Client retry behavior to allow for a configurable backoff multiplier.

Previously, the backoff multiplier (named r in the code) was set to 2 seconds. This is not an ideal default for services like DynamoDB that expect clients to quickly retry failed request attempts. Now, users can set quicker (or slower) multipliers according to their needs.

#[tokio::main]
async fn main() -> Result<(), aws_sdk_dynamodb::Error> {
    let retry_config = aws_smithy_types::retry::RetryConfigBuilder::new()
        .max_attempts(4)
        .backoff_multiplier(Duration::from_millis(20));

    let shared_config = aws_config::from_env()
        .retry_config(retry_config)
        .load()
        .await;

    let client = aws_sdk_dynamodb::Client::new(&shared_config);

    // Given the 20ms backoff multiplier, and assuming this request fails 3 times before succeeding,
    // the first retry would take place between 0-20ms after the initial request,
    // the second retry would take place between 0-40ms after the first retry,
    // and the third retry would take place between 0-80ms after the second retry.
    let request = client
        .put_item()
        .table_name("users")
        .item("username", "Velfi")
        .item("account_type", "Developer")
        .send().await?;

    Ok(())
}

For a request that gets retried 3 times, when base is 1 and initial_backoff is 2 seconds:

  • the first retry will occur after 0 to 2 seconds
  • the second retry will occur after 0 to 4 seconds
  • the third retry will occur after 0 to 8 seconds

For a request that gets retried 3 times, when base is 1 and initial_backoff is 30 milliseconds:

  • the first retry will occur after 0 to 30 milliseconds
  • the second retry will occur after 0 to 60 milliseconds
  • the third retry will occur after 0 to 120 milliseconds

Testing

I wrote some test for the backoff calculation and ran existing retry tests

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

update: smithy client to respect configurable backoff
update: CHANGELOG.next.toml
@Velfi Velfi marked this pull request as draft July 12, 2022 22:20
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@Velfi Velfi marked this pull request as ready for review July 12, 2022 22:49
@Velfi Velfi marked this pull request as draft July 13, 2022 16:12
Zelda Hessler added 2 commits July 13, 2022 09:55
update: default backoff multiplier to be 1 second to better match previous retry behavior
@Velfi Velfi marked this pull request as ready for review July 13, 2022 16:56
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

this looks great! the one change I'd make is considering renaming with_backoff_multiplier to initial_backoff—it's what we call it in the interior code and I think it's a bit more grokable. But totally open to discuss this

update: calculate_exponential_backoff tests for readability
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.


[[aws-sdk-rust]]
message = """
Updated SDK Client retry behavior to allow for a configurable backoff multiplier. Previously, the backoff multiplier
Copy link
Collaborator

Choose a reason for hiding this comment

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

backoff multiplier -> initial delay

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

Nice! LGTM

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@Velfi Velfi merged commit e6005fb into main Jul 15, 2022
@Velfi Velfi deleted the feature/configurable-retry-base-multiplier branch July 15, 2022 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants