Memory cache eviction is inefficient and error-prone #14311
Labels
⚠️bug?
This might be a bug
packages/backend
Server side specific issue/PR
🐢Performance
Efficiency related issue/PR
💡 Summary
Cache eviction from
MemoryKVCache<T>
is currently based on a hard-coded 3 minute timer. When this timer ticks, thegc()
method loops through all entries and removes any that have been evicted. This has a few issues:This can be solved by modifying the implementation to create a new timer per entry. When one of these timers ticks, it removes the associated row without any loops or checks. The timer ID can be stored within the cache entry and automatically cancelled when the entry is deleted. This has three benefits:
This bug was first discovered in the Sharkey fork, but exists in Misskey as well. For additional details, see Sharkey issue #601 and Sharkey MR #580.
Related to #14310.
🥰 Expected Behavior
Cache eviction should be predictable and not consume significant system resources.
🤬 Actual Behavior
Cache eviction is slow and inconsistent.
📝 Steps to Reproduce
Run a federated instance for an extended period of time and wait for caches to fill. The "garbage collection" process will consume a notable amount of CPU time every 3 minutes or so.
💻 Frontend Environment
🛰 Backend Environment (for server admin)
Do you want to address this bug yourself?
The text was updated successfully, but these errors were encountered: