Skip to main content

Module pool

Module pool 

Source
Expand description

The pool: a Send blueprint you build once and clone onto every thread, and the strictly thread-local pool it stamps out on each.

Pool holds nothing hot — only the manager, the configuration, a shutdown flag and a registry of per-thread metrics blocks, behind one Arc. Cloning it is an Arc bump. The connections, the idle list and the slot count all live in the LocalPool that Pool::local creates on a thread: Rc and Cell, no lock and no atom on the hot path, never Send. The type system then stops a connection — bound to one ring — from ever leaving its thread.

§Metrics across threads

Each LocalPool owns one [Metrics] block and registers a clone of it with the Pool. Only the owning thread ever writes its block, so the counters are plain relaxed atomics with no cross-thread contention. Pool::state and Pool::statistics lock the registry — a cold path — and sum every block to give a process-wide view; LocalPool::state and LocalPool::statistics read only this thread’s block.

Structs§

LocalPool
One thread’s pool, created by Pool::local.
Pool
A blueprint for per-thread pools: build it once, clone it onto each compio thread you spawn, and call local there.
PooledConnection
A connection checked out of its LocalPool. Derefs to the connection; dropping it runs has_broken and either returns the connection to this thread’s idle list or drops it and frees the slot. If the pool has been closed, the connection is always dropped.
State
A snapshot of live connection counts. From LocalPool::state it is one thread’s; from Pool::state it is the sum across every thread.
Statistics
Cumulative counters over a pool’s life. From LocalPool::statistics it is one thread’s; from Pool::statistics it is the sum across every thread.