distribute/connection_pool

Types

Result of batch operations with error aggregation

pub type BatchResult(e) {
  BatchResult(
    total: Int,
    successful: Int,
    failed: Int,
    errors: List(e),
  )
}

Constructors

  • BatchResult(
      total: Int,
      successful: Int,
      failed: Int,
      errors: List(e),
    )

Connection handle from a pool

pub type Connection

Connection pool handle (backed by ETS table)

pub type Pool

Pool operation errors

pub type PoolError {
  PoolExhausted
  ConnectionFailed(String)
  InvalidConfig(String)
  InvalidPool
}

Constructors

  • PoolExhausted

    Pool has reached maximum connections

  • ConnectionFailed(String)

    Connection establishment failed

  • InvalidConfig(String)

    Invalid pool configuration

  • InvalidPool

    Pool was destroyed or invalid

Pool statistics

pub type PoolStats {
  PoolStats(
    target_node: String,
    max_connections: Int,
    active_connections: Int,
    available_connections: Int,
  )
}

Constructors

  • PoolStats(
      target_node: String,
      max_connections: Int,
      active_connections: Int,
      available_connections: Int,
    )

Values

pub fn destroy(pool: Pool) -> Result(Nil, PoolError)

Destroy the pool and release all resources

pub fn new(
  target_node: String,
  max_connections: Int,
) -> Result(Pool, PoolError)

Create a new connection pool backed by ETS for atomic operations

pub fn send_batch(
  pool: Pool,
  messages: List(#(String, a)),
  send_fn: fn(String, a) -> Result(Nil, b),
) -> Result(List(Result(Nil, b)), PoolError)

Send multiple messages in a batch using a single connection

pub fn send_batch_parallel(
  pool: Pool,
  messages: List(#(String, a)),
  send_fn: fn(String, a) -> Result(Nil, b),
) -> Result(BatchResult(b), PoolError)

Send multiple messages in parallel (up to pool size) with error aggregation

pub fn stats(pool: Pool) -> Result(PoolStats, PoolError)

Get pool statistics (atomic read from ETS)

pub fn stress_test(
  pool: Pool,
  ops_per_worker: Int,
  workers: Int,
) -> Result(PoolStats, PoolError)

Run a concurrency stress-test against a pool. This spawns multiple worker processes each performing ops get/release cycles using the pool; returns final pool stats.

pub fn with_connection(
  pool: Pool,
  f: fn(Connection) -> a,
) -> Result(a, PoolError)

Execute a function with a pooled connection (automatically released)

Search Document