pub struct RateLimiter { /* private fields */ }Expand description
Rate limiter for controlling API call frequency and concurrency
Provides dual-level throttling: semaphore-based concurrency control and time-based rate limiting for both LLM and embedding API calls.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: &AsyncConfig) -> Self
pub fn new(config: &AsyncConfig) -> Self
Creates a new rate limiter from configuration
Initializes semaphores and rate trackers for both LLM and embedding API calls.
§Parameters
config: Configuration specifying concurrency and rate limits
Sourcepub async fn acquire_llm_permit(
&self,
) -> Result<SemaphorePermit<'_>, GraphRAGError>
pub async fn acquire_llm_permit( &self, ) -> Result<SemaphorePermit<'_>, GraphRAGError>
Acquires a permit for making an LLM API call
Blocks until both concurrency and rate limits allow the call to proceed. The permit must be held for the duration of the API call and will be released when dropped.
§Returns
Semaphore permit on success, or an error if acquisition fails
Sourcepub async fn acquire_embedding_permit(
&self,
) -> Result<SemaphorePermit<'_>, GraphRAGError>
pub async fn acquire_embedding_permit( &self, ) -> Result<SemaphorePermit<'_>, GraphRAGError>
Acquires a permit for making an embedding API call
Blocks until both concurrency and rate limits allow the call to proceed. The permit must be held for the duration of the API call and will be released when dropped.
§Returns
Semaphore permit on success, or an error if acquisition fails
Sourcepub fn get_available_llm_permits(&self) -> usize
pub fn get_available_llm_permits(&self) -> usize
Returns the number of available LLM permits
§Returns
Number of LLM API calls that can be made immediately without waiting
Sourcepub fn get_available_embedding_permits(&self) -> usize
pub fn get_available_embedding_permits(&self) -> usize
Returns the number of available embedding permits
§Returns
Number of embedding API calls that can be made immediately without waiting
Sourcepub fn health_check(&self) -> ComponentStatus
pub fn health_check(&self) -> ComponentStatus
Performs a health check on the rate limiter
Checks permit availability to determine if the system is healthy or experiencing congestion.
§Returns
Component status indicating health (Healthy, Warning, or Error)
Sourcepub fn get_config(&self) -> &AsyncConfig
pub fn get_config(&self) -> &AsyncConfig
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin for RateLimiter
impl !UnwindSafe for RateLimiter
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
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>
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>
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