diff --git a/aws-s3-transfer-manager/src/middleware/hedge.rs b/aws-s3-transfer-manager/src/middleware/hedge.rs index ab145de6..f2e1cf0d 100644 --- a/aws-s3-transfer-manager/src/middleware/hedge.rs +++ b/aws-s3-transfer-manager/src/middleware/hedge.rs @@ -20,13 +20,13 @@ const MIN_DATA_POINTS: u64 = 20; const PERIOD: Duration = Duration::from_secs(2); /* -* During uploads, S3 recommends retrying the slowest 5% of requests for latency-sensitive applications, -* as some requests can experience high time to first byte. If a slow part is hit near the end of the request, -* the application may spend the last few seconds waiting for those final parts to complete, which can reduce overall -* throughput. This layer is used to retry the slowest 5% of requests to improve performance. -* Based on our experiments, this makes a significant difference for multipart upload use-cases and -* does not have a noticeable impact for the Download. -*/ + * During uploads, S3 recommends retrying the slowest 5% of requests for latency-sensitive applications, + * as some requests can experience high time to first byte. If a slow part is hit near the end of the request, + * the application may spend the last few seconds waiting for those final parts to complete, which can reduce overall + * throughput. This layer is used to retry the slowest 5% of requests to improve performance. + * Based on our experiments, this makes a significant difference for multipart upload use-cases and + * does not have a noticeable impact for the Download. + */ pub(crate) struct Builder
{ policy: P, latency_percentile: f32, @@ -34,31 +34,16 @@ pub(crate) struct Builder
{
period: Duration,
}
-#[derive(Debug, Clone, Default)]
-pub(crate) struct DefaultPolicy;
-
-impl Builder {
+ pub(crate) fn new(policy: P) -> Self {
Self {
- policy: DefaultPolicy,
+ policy,
latency_percentile: LATENCY_PERCENTILE,
min_data_points: MIN_DATA_POINTS,
period: PERIOD,
}
}
-}
-impl Builder {
/// Converts the `Hedge` into a `Layer` that can be used in a service stack.
pub(crate) fn into_layer> + Clone
where
diff --git a/aws-s3-transfer-manager/src/operation/upload/service.rs b/aws-s3-transfer-manager/src/operation/upload/service.rs
index dcbd79c2..640eff06 100644
--- a/aws-s3-transfer-manager/src/operation/upload/service.rs
+++ b/aws-s3-transfer-manager/src/operation/upload/service.rs
@@ -1,5 +1,6 @@
use std::sync::Arc;
+use super::MultipartUploadData;
use crate::{
error,
io::{
@@ -12,11 +13,9 @@ use crate::{
use aws_sdk_s3::{primitives::ByteStream, types::CompletedPart};
use bytes::Buf;
use tokio::{sync::Mutex, task};
-use tower::{service_fn, Service, ServiceBuilder, ServiceExt};
+use tower::{hedge::Policy, service_fn, Service, ServiceBuilder, ServiceExt};
use tracing::Instrument;
-use super::MultipartUploadData;
-
/// Request/input type for our "upload_part" service.
#[derive(Debug, Clone)]
pub(super) struct UploadPartRequest {
@@ -25,6 +24,22 @@ pub(super) struct UploadPartRequest {
pub(super) upload_id: String,
}
+#[derive(Debug, Clone)]
+pub(crate) struct UploadHedgePolicy;
+
+impl Policy