Expand description
Browser instance pool with warmup, health checks, and idle eviction
§Architecture
┌──────────────────────────────────────────────────────┐
│ BrowserPool │
│ │
│ Semaphore (max_size slots) │
│ ┌──────────────────────────────────────────────┐ │
│ │ idle: VecDeque<PoolEntry> │ │
│ │ entry: { instance, last_used: Instant } │ │
│ └──────────────────────────────────────────────┘ │
│ active_count: Arc<AtomicUsize> │
└──────────────────────────────────────────────────────┘Acquisition flow
- Try to pop a healthy idle entry.
- If none idle and
active < max_size, launch a freshBrowserInstance. - Otherwise wait up to
acquire_timeoutfor an idle slot.
Release flow
- Run a health-check on the returned instance.
- If healthy and
idle < max_size, push it back to the idle queue. - Otherwise shut it down and decrement the active counter.
§Example
use stygian_browser::{BrowserConfig, BrowserPool};
let config = BrowserConfig::default();
let pool = BrowserPool::new(config).await?;
let stats = pool.stats();
println!("Pool ready — idle: {}", stats.idle);
let handle = pool.acquire().await?;
handle.release().await;Structs§
- Browser
Handle - An acquired browser from the pool.
- Browser
Pool - Thread-safe pool of reusable
BrowserInstances. - Pool
Stats - Point-in-time metrics for a
BrowserPool.