6 ms·
> On startup, 128 request and response objects are pre-allocated in per-thread pools. As a request comes in, one of them is checked out, populated, and handed o
by JoshMcguigan 7y ago
> On startup, 128 request and response objects are pre-allocated in per-thread pools. As a request comes in, one of them is checked out, populated, and handed off to user code. When that code finishes with it and the object is going out of scope, Drop kicks in and checks it back into the pool for reuse. New objects are allocated only when pools are exhausted, thereby saving many needless memory allocations and deallocations as a web server handles normal traffic load.
As someone not very familiar with systems programming, I would have expected this is an optimization that would already happen automatically within the system memory allocator. Is that not the case?
- fafhrd91 7y agoYou still need to initialize inner structures and buffers. Cache allows to avoid that.
- JoshMcguigan 7y agoThanks for the response. So it sounds like it is not so much the allocation/de-allocation savings that matters, but rather that you get to skip initializing the memory because it is already known to be a valid instance of a given struct type?
- jlokier 7y agoYes, that. See also SLAB allocation, used in many OS kernels: https://en.wikipedia.org/wiki/Slab_allocation https://en.wikipedia.org/wiki/Slab_allocation