pub struct ConcurrentLimitLayer<S: ConcurrentLimitSemaphore = Arc<Semaphore>> { /* private fields */ }Expand description
Add concurrent request limit.
§Notes
Users can control how many concurrent connections could be established between OpenDAL and underlying storage services.
All operators wrapped by this layer will share a common semaphore. This allows you to reuse the same layer across multiple operators, ensuring that the total number of concurrent requests across the entire application does not exceed the limit.
§Examples
Add a concurrent limit layer to the operator:
let _ = Operator::new(services::Memory::default())?
.layer(ConcurrentLimitLayer::new(1024))
.finish();Share a concurrent limit layer between the operators:
let limit = ConcurrentLimitLayer::new(1024);
let _operator_a = Operator::new(services::Memory::default())?
.layer(limit.clone())
.finish();
let _operator_b = Operator::new(services::Memory::default())?
.layer(limit.clone())
.finish();Implementations§
Source§impl ConcurrentLimitLayer<Arc<Semaphore>>
impl ConcurrentLimitLayer<Arc<Semaphore>>
Sourcepub fn new(permits: usize) -> Self
pub fn new(permits: usize) -> Self
Create a new ConcurrentLimitLayer with the specified number of
permits.
These permits will be applied to all operations.
Sourcepub fn with_http_concurrent_limit(self, permits: usize) -> Self
pub fn with_http_concurrent_limit(self, permits: usize) -> Self
Set a concurrent limit for HTTP requests.
This convenience helper constructs a new semaphore with the specified
number of permits and calls ConcurrentLimitLayer::with_http_semaphore.
Use ConcurrentLimitLayer::with_http_semaphore directly when reusing
a shared semaphore.
Source§impl<S: ConcurrentLimitSemaphore> ConcurrentLimitLayer<S>
impl<S: ConcurrentLimitSemaphore> ConcurrentLimitLayer<S>
Sourcepub fn with_semaphore(operation_semaphore: S) -> Self
pub fn with_semaphore(operation_semaphore: S) -> Self
Create a layer with any ConcurrentLimitSemaphore implementation.
let semaphore = Arc::new(Semaphore::new(1024));
let _layer = ConcurrentLimitLayer::with_semaphore(semaphore);Sourcepub fn with_http_semaphore(self, semaphore: S) -> Self
pub fn with_http_semaphore(self, semaphore: S) -> Self
Provide a custom HTTP concurrency semaphore instance.
Trait Implementations§
Source§impl<S: Clone + ConcurrentLimitSemaphore> Clone for ConcurrentLimitLayer<S>
impl<S: Clone + ConcurrentLimitSemaphore> Clone for ConcurrentLimitLayer<S>
Source§fn clone(&self) -> ConcurrentLimitLayer<S>
fn clone(&self) -> ConcurrentLimitLayer<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more