2025-02-16, 05:06 AM
I have been struggling with an issue for over a year now.
Despite having a server with 32GB of RAM, my server runs out of memory daily, Specifically the Jellyfin service consumes all available ram. and I've noticed that I'm forced to restart the server service every day just to keep it running.
After some digging into the source, I suspect the root of the problem lies in how the LibraryManager handles caching.
From what I gathered in the LibraryManager.cs source code, the application uses a ConcurrentDictionary to store every media item that's registered via the RegisterItem method.
Once an item is added to this cache, it stays there for the lifetime of the server process because there's no expiration or eviction policy in place.
Over time, especially as the media library grows (mine is well in the 10,000 range), this cache keeps accumulating items, which eventually leads to memory exhaustion.
I’ve also noticed that this issue becomes even more pronounced when using tools that scan the library for missing content or applications like jellyseerr (I actually run a separate server just for this now).
It seems that these operations increase the rate at which new items are cached, thereby accelerating the memory leak.
I believe that adding a better way to manage this cache—perhaps by introducing an eviction strategy such as a Time-To-Live (TTL) or Least Recently Used (LRU) policy—could make a big difference.
It might also help to allow users to select the level of caching based on their environment and needs, which would go a long way toward scaling the application.
I have read a few posts in the help section where some think ever expanding cache is a good thing. I am not in this camp. Cache only makes sense when it is very targeted and should allow the application to respect the server and other potential applications.
Thanks for taking the time to read this. I hope this information is useful.
Despite having a server with 32GB of RAM, my server runs out of memory daily, Specifically the Jellyfin service consumes all available ram. and I've noticed that I'm forced to restart the server service every day just to keep it running.
After some digging into the source, I suspect the root of the problem lies in how the LibraryManager handles caching.
From what I gathered in the LibraryManager.cs source code, the application uses a ConcurrentDictionary to store every media item that's registered via the RegisterItem method.
Once an item is added to this cache, it stays there for the lifetime of the server process because there's no expiration or eviction policy in place.
Over time, especially as the media library grows (mine is well in the 10,000 range), this cache keeps accumulating items, which eventually leads to memory exhaustion.
I’ve also noticed that this issue becomes even more pronounced when using tools that scan the library for missing content or applications like jellyseerr (I actually run a separate server just for this now).
It seems that these operations increase the rate at which new items are cached, thereby accelerating the memory leak.
I believe that adding a better way to manage this cache—perhaps by introducing an eviction strategy such as a Time-To-Live (TTL) or Least Recently Used (LRU) policy—could make a big difference.
It might also help to allow users to select the level of caching based on their environment and needs, which would go a long way toward scaling the application.
I have read a few posts in the help section where some think ever expanding cache is a good thing. I am not in this camp. Cache only makes sense when it is very targeted and should allow the application to respect the server and other potential applications.
Thanks for taking the time to read this. I hope this information is useful.