Description
(inspired by Hal H, Alex F, on discussion for use at SFDC)
Current chunk allocation scheme has the benefit of allowing much of the memory to be returned to OS when not needed, depending on constraints defined for individual queues (i.e. if they can grow/shrink). But it has potentially non-trivial overhead as chunks need bit of JVM overhead for tracking.
On the other hand, allocating bigger "slabs" (piece of memory that is multiple of chunk) would make it possible to reduce such overhead. But it will be next to impossible to free such chunks before closing down individual "MemBuffers" instances, because likelihood of at least one chunk of a slab being in use is high.
So in practice such slabs would be static; allocated when needed (or eagerly), and not freed for lifetime of individual Buffers instance (factory of group of individual queues).
One simple and seemingly efficient way to make use of this would be to allow specifying amount of "static" memory (as number of chunks) that may be allocated, and use this for allocation slabs. Chunks from slabs would then be the primary source of allocation; and dynamic (individual) chunks would only be allocated if slabs are full.
Conversely, slab-based chunks would always be reusable; whereas reuse rate for dynamic chunks could be more closely limited.
Activity