pub struct HostPool { /* private fields */ }Expand description
Manages a pool of Host instances and routes requests to appropriate hosts.
The HostPool serves as the central coordinator for per-host rate limiting.
It creates host instances on-demand and provides a unified interface for
executing HTTP requests with appropriate rate limiting applied.
§Architecture
- Each unique hostname gets its own Host instance with dedicated rate limiting
- Hosts are created lazily when first requested
- Thread-safe using
DashMapfor concurrent access to host instances
Implementations§
Source§impl HostPool
impl HostPool
Sourcepub fn new(
global_config: RateLimitConfig,
host_configs: HostConfigs,
default_client: Client,
client_map: ClientMap,
) -> Self
pub fn new( global_config: RateLimitConfig, host_configs: HostConfigs, default_client: Client, client_map: ClientMap, ) -> Self
Create a new HostPool with the given configuration
Sourcepub fn host_stats(&self, hostname: &str) -> HostStats
pub fn host_stats(&self, hostname: &str) -> HostStats
Returns statistics for the host if it exists, otherwise returns empty stats. This provides consistent behavior whether or not requests have been made to that host yet.
Sourcepub fn all_host_stats(&self) -> HostStatsMap
pub fn all_host_stats(&self) -> HostStatsMap
Returns a HashMap mapping hostnames to their statistics.
Only hosts that have had requests will be included.
Sourcepub fn active_host_count(&self) -> usize
pub fn active_host_count(&self) -> usize
Get the number of host instances that have been created, which corresponds to the number of unique hostnames that have been accessed.
Sourcepub fn host_configurations(&self) -> HostConfigs
pub fn host_configurations(&self) -> HostConfigs
Get a copy of the current host-specific configurations. This is useful for debugging or runtime monitoring of configuration.
Sourcepub fn remove_host(&self, hostname: &str) -> bool
pub fn remove_host(&self, hostname: &str) -> bool
Remove a host from the pool.
This forces the host to be recreated with updated configuration the next time a request is made to it. Any ongoing requests to that host will continue with the old instance.
§Returns
Returns true if a host was removed, false if no host existed for that hostname.
Sourcepub fn cache_stats(&self) -> HashMap<String, (usize, f64)>
pub fn cache_stats(&self) -> HashMap<String, (usize, f64)>
Get cache statistics across all hosts
Sourcepub fn record_persistent_cache_hit(&self, uri: &Uri)
pub fn record_persistent_cache_hit(&self, uri: &Uri)
Record a cache hit for the given URI in host statistics. This tracks that a request was served from the persistent disk cache. Note that no equivalent function for tracking cache misses is exposed, since this is handled internally.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HostPool
impl !RefUnwindSafe for HostPool
impl Send for HostPool
impl Sync for HostPool
impl Unpin for HostPool
impl !UnwindSafe for HostPool
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