macula_peer_connection_pool (macula v0.20.5)
View SourcePeer Connection Pool - Manages pooled QUIC connections to remote peers.
Problem: Creating a new QUIC connection per message adds ~50-200ms latency. Solution: Pool connections and reuse them for subsequent messages.
Design: - ETS-based connection pool for O(1) lookups - LRU eviction when pool is full - Automatic connection health monitoring - Configurable pool size and idle timeout
Expected improvement: 1.5-2x latency reduction for repeated messaging.
Summary
Functions
Get list of peer IDs with active connections. Returns list of peer IDs that have pooled connections.
Get a connection to an endpoint (from pool or create new). Returns {ok, Connection, Stream} or {error, Reason}.
Invalidate (remove) a connection from the pool. Called when a connection fails or is no longer valid.
Put a connection directly into the pool (NAT system API). Used by connection upgrade to store successfully upgraded direct connections.
Return a connection to the pool for reuse.
Start the connection pool with default options.
Start the connection pool with options. Options: - max_connections: Maximum pooled connections (default: 100) - idle_timeout_ms: Idle connection timeout (default: 60000)
Get pool statistics.
Functions
-spec get_connected_peers() -> [binary()].
Get list of peer IDs with active connections. Returns list of peer IDs that have pooled connections.
Get a connection to an endpoint (from pool or create new). Returns {ok, Connection, Stream} or {error, Reason}.
-spec invalidate(binary()) -> ok.
Invalidate (remove) a connection from the pool. Called when a connection fails or is no longer valid.
Put a connection directly into the pool (NAT system API). Used by connection upgrade to store successfully upgraded direct connections.
Return a connection to the pool for reuse.
Start the connection pool with default options.
Start the connection pool with options. Options: - max_connections: Maximum pooled connections (default: 100) - idle_timeout_ms: Idle connection timeout (default: 60000)
-spec stats() -> map().
Get pool statistics.