Skip to main content

Module pool

Module pool 

Source
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

  1. Try to pop a healthy idle entry.
  2. If none idle and active < max_size, launch a fresh BrowserInstance.
  3. Otherwise wait up to acquire_timeout for an idle slot.

Release flow

  1. Run a health-check on the returned instance.
  2. If healthy and idle < max_size, push it back to the idle queue.
  3. 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§

BrowserHandle
An acquired browser from the pool.
BrowserPool
Thread-safe pool of reusable BrowserInstances.
PoolStats
Point-in-time metrics for a BrowserPool.