-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
globalize concurrency management (#55)
- Loading branch information
Showing
16 changed files
with
518 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
pub(crate) mod limit; | ||
pub(crate) mod retry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
pub(crate) mod concurrency; |
15 changes: 15 additions & 0 deletions
15
aws-s3-transfer-manager/src/middleware/limit/concurrency.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//! Limit the maximum number of requests being concurrently processed by a service. | ||
//! | ||
//! This middleware is similar to the `tower::limit::concurrency` middleware but goes through | ||
//! the transfer manager scheduler to control concurrency rather than just a semaphore. | ||
mod future; | ||
mod layer; | ||
mod service; | ||
|
||
pub(crate) use self::layer::ConcurrencyLimitLayer; |
37 changes: 37 additions & 0 deletions
37
aws-s3-transfer-manager/src/middleware/limit/concurrency/future.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use crate::runtime::scheduler::OwnedWorkPermit; | ||
|
||
use futures_util::ready; | ||
use pin_project_lite::pin_project; | ||
use std::{future::Future, task::Poll}; | ||
|
||
pin_project! { | ||
#[derive(Debug)] | ||
pub(crate) struct ResponseFuture<T> { | ||
#[pin] | ||
inner: T, | ||
// retain until dropped when future completes | ||
_permit: OwnedWorkPermit | ||
} | ||
} | ||
|
||
impl<T> ResponseFuture<T> { | ||
pub(crate) fn new(inner: T, _permit: OwnedWorkPermit) -> ResponseFuture<T> { | ||
ResponseFuture { inner, _permit } | ||
} | ||
} | ||
|
||
impl<F, T, E> Future for ResponseFuture<F> | ||
where | ||
F: Future<Output = Result<T, E>>, | ||
{ | ||
type Output = Result<T, E>; | ||
|
||
fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> { | ||
Poll::Ready(ready!(self.project().inner.poll(cx))) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
aws-s3-transfer-manager/src/middleware/limit/concurrency/layer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use crate::runtime::scheduler::Scheduler; | ||
use tower::Layer; | ||
|
||
use super::service::ConcurrencyLimit; | ||
|
||
/// Enforces a limit on the concurrent number of requests the underlying | ||
/// service can handle. | ||
#[derive(Debug, Clone)] | ||
pub(crate) struct ConcurrencyLimitLayer { | ||
scheduler: Scheduler, | ||
} | ||
|
||
impl ConcurrencyLimitLayer { | ||
/// Create a new concurrency limit layer. | ||
pub(crate) const fn new(scheduler: Scheduler) -> Self { | ||
ConcurrencyLimitLayer { scheduler } | ||
} | ||
} | ||
|
||
impl<S> Layer<S> for ConcurrencyLimitLayer { | ||
type Service = ConcurrencyLimit<S>; | ||
|
||
fn layer(&self, service: S) -> Self::Service { | ||
ConcurrencyLimit::new(service, self.scheduler.clone()) | ||
} | ||
} |
Oops, something went wrong.