-
Notifications
You must be signed in to change notification settings - Fork 2
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
globalize concurrency management #55
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1b38c7b
basic scheduling abstraction
aajtodd 7c579c4
wip concurrency service
aajtodd 2c4b4a8
fill in future and layer
aajtodd 8f32cae
add some sanity tests
aajtodd 0589973
cleanup
aajtodd d516582
replace tower concurrency limit with custom scheduler
aajtodd 68da7f1
make discovery go through scheduler
aajtodd 1649afd
remove todo
aajtodd 2960c01
fix default concurrency and add impl note
aajtodd 7fe216d
fix rebase
aajtodd 86f12a0
define explicit third state
aajtodd b2f5d36
Merge remote-tracking branch 'origin/main' into atodd/globalize
aajtodd 0a79789
add clarification comment
aajtodd 14b74f9
cleanup fixme/todo comments
aajtodd dc56f55
restrict visibility
aajtodd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall code structure is confusing. We have
middleware/limit/
andmiddleware/limit/concurrency
, but it contains the ConcurrencyLimit service. I am a bit confused about why we don't have something simpler likemiddleware/concurrency_limit.rs
,middleware/concurrency_limit/*
and get rid of limit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. I sort of just followed tokio's existing module structure (they have both a concurrency limit and a rate limit middleware and thus both are under the
limit
module). I don't have a strong opinion on this one.