Note: In browsers, pooling typically means one shared socket per origin (SharedWorker / BroadcastChannel). In Node, a pool of N outbound WS connections to a backend service.
2. Creating Connection Pool
Example: Simple Node pool
class WsPool { constructor(url, size = 4) { this.size = size; this.url = url; this.idle = []; this.busy = new Set(); for (let i = 0; i < size; i++) this.idle.push(this.#create()); } #create() { return new WebSocket(this.url); } acquire() { const c = this.idle.shift() ?? this.#create(); this.busy.add(c); return c; } release(c) { this.busy.delete(c); this.idle.push(c); }}
3. Acquiring Connections
Strategy
Detail
FIFO
Round-robin fairness
LIFO
Recently active = warm
Least-busy
Lowest bufferedAmount
Wait queue
If all busy, queue with timeout
4. Releasing Connections
Action
Detail
Return to idle
If healthy
Discard
If errored / closed
Replace
Spawn new one in background
5. Setting Pool Size Limits
Side
Concern
Browser per-origin
~6 HTTP/1.1; WS not strictly limited but practical cap