pub struct ConcurrencyController { /* private fields */ }Expand description
Concurrency controller for LLM API calls.
Combines:
- Rate Limiter — Token bucket to limit requests per time period
- Semaphore — Limit concurrent requests
§Example
use vectorless::throttle::{ConcurrencyController, ConcurrencyConfig};
let config = ConcurrencyConfig::default();
let controller = ConcurrencyController::new(config);
// Before making an API call
let permit = controller.acquire().await;
// Make the API call...
drop(permit); // Release when doneImplementations§
Source§impl ConcurrencyController
impl ConcurrencyController
Sourcepub fn new(config: ConcurrencyConfig) -> Self
pub fn new(config: ConcurrencyConfig) -> Self
Create a new concurrency controller with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a controller with default configuration.
Sourcepub fn high_throughput() -> Self
pub fn high_throughput() -> Self
Create a controller for high-throughput scenarios.
Sourcepub fn conservative() -> Self
pub fn conservative() -> Self
Create a controller for conservative scenarios.
Sourcepub async fn acquire(&self) -> Option<SemaphorePermit<'_>>
pub async fn acquire(&self) -> Option<SemaphorePermit<'_>>
Acquire a permit for making an LLM request.
This will:
- Wait for the rate limiter (if enabled)
- Acquire a semaphore permit (if enabled)
The permit is automatically released when dropped.
Sourcepub fn try_acquire(&self) -> Option<SemaphorePermit<'_>>
pub fn try_acquire(&self) -> Option<SemaphorePermit<'_>>
Try to acquire a permit without waiting.
Returns None if the limit is reached.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Get the number of available semaphore permits.
Sourcepub fn config(&self) -> &ConcurrencyConfig
pub fn config(&self) -> &ConcurrencyConfig
Get the configuration.
Sourcepub fn rate_limiter(&self) -> Option<&RateLimiter>
pub fn rate_limiter(&self) -> Option<&RateLimiter>
Get the rate limiter (if any).
Trait Implementations§
Source§impl Clone for ConcurrencyController
impl Clone for ConcurrencyController
Source§fn clone(&self) -> ConcurrencyController
fn clone(&self) -> ConcurrencyController
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ConcurrencyController
impl Debug for ConcurrencyController
Auto Trait Implementations§
impl Freeze for ConcurrencyController
impl !RefUnwindSafe for ConcurrencyController
impl Send for ConcurrencyController
impl Sync for ConcurrencyController
impl Unpin for ConcurrencyController
impl UnsafeUnpin for ConcurrencyController
impl !UnwindSafe for ConcurrencyController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more