IO::BufferPool
A pool of reusable byte buffers for IO::Buffered.
Most connections are idle most of the time. By returning read/write buffers to a pool when they're not in use, memory can be reused across connections instead of each connection holding two buffers forever.
Each thread has its own cache of buffers (a LIFO stack, so the most recently
used buffer is reused first), so acquiring and releasing takes no locks.
A buffer may be released on another thread than it was acquired on, it then
goes into that thread's cache. Each cache keeps at most
CACHE_BYTES_PER_THREAD worth of buffers, more are left to the GC.
Constants
Idle buffers kept per thread and pool: 256 buffers of the default 16 KiB. With hundreds of busy connections, about 350 buffers were in use at once, and 64 buffers made the pool drop and reallocate some of them.
Constructors
Class methods
Returns the pool for the given buffer size. Pools for other sizes (from
before a config reload) keep serving the connections that use them, their
caches are bounded by CACHE_BYTES_PER_THREAD.
Instance methods
Return a buffer to the current thread's cache. If the cache is full, the buffer is left for the GC.