EVaillant / lockfree-object-pool

Object Pool LockFree in Rust
Boost Software License 1.0
44 stars 2 forks source link

Add capability to dynamically shrink an object pool #3

Closed carllin closed 10 months ago

carllin commented 3 years ago

It would be convenient to be able to periodically free the unused objects in the pool to deal with elastic workloads.

For example, let's say we periodically check if the unused objects comprise > X% of the total number of allocations for an extended period of time. If > N of these checks return true, it would be nice to then shrink the pool to reduce memory usage.

For instance, in LinearObjectPool, we 1) Tracked an additional pointer shrink_target representing the node representing X% in the list, 2) New Page's have a pointer to the shrink_target at the time they were added 3) we could implement the shrink by updating head -> shrink_target, shrink_target -> shrink_target's shrink_target

EVaillant commented 3 years ago

nice idea

But I'm not fan of period of time, I prefer to have a method shrink or auto detect after a pull or release. I think implementation will be complicated (in LinearObjectPool) be cause shrink could be in // with pull.