Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run periodically forces Go's garbage collector and tries to return freed pages back to the OS. ---------------------------------------------- Why is this needed?
This service is a high-load in-memory cache. Once the cache reaches its target size (e.g., 10-20 million keys), the heap stabilizes at a large size — for example, 18 GB. By default, Go's GC will only run a full collection if the heap grows by GOGC% (default 100%). This means the next GC cycle could be delayed until the heap doubles again (e.g., 36 GB).
For a cache, this almost never happens: the cache keeps its "critical mass" and rarely doubles in size, but in the meantime, temporary buffers and evicted objects create garbage. If no GC happens, this garbage is never reclaimed, so the process appears to "leak" memory.
To prevent this, we force `runtime.GC()` on a short interval, and periodically call `debug.FreeOSMemory()` to push freed pages back to the OS. Both intervals are configurable in the config.
This guarantees:
- predictable and stable memory usage
- less surprise RSS growth during steady state
- smoother operation for long-lived caches under high load.
Types ¶
This section is empty.