Cross-posting from my Reddit Post ![]()
tl;dr A caching tool that uses on-demand FUSE overmount to intercept I/O syscalls and predictively cache shows your users are watching.
I’ve been a longtime lurker and have used Plex for more than a decade, I thought this might’ve been something useful for others.
A bigger read
Hey everyone, I’ve been a Plex host for years. My hard drive arrays have grown very large and I’ve been investing myself into tuning power savings as much as possible - electricity is expensive in SoCal. One of my recent experiments was building tiered caching for my server (which works great with MergerFS). This got me thinking about how I could cache files directly on Plex itself. I browsed online, but I was unable to find anything that fit my use-case very closely (or they had an overly complex setup for something that’s quite simple).
Introducing plex-hot-cache. I created my own binary that serves my purpose of caching hot media files during maintenance hours. It looks at what Plex is accessing from your backing drives and predictively loads the next n episodes from the backing drives onto the SSD Cache. This improves performance of the server and prevents your backing drives from waking up randomly from people binging TV shows. There are a number of settings that you can tweak to tailor the binary to your use case.
One of my main principles when developing this was that it could be dropped in and closed whenever the user wants. You can literally download the binary, run it and it “just works”. It uses FUSE overmounting features (this is a godsend, I surely need to thank the person that developed this) and gracefully exits when you want as long as a signal is caught (ex. ctrl-c or hitting the X). It won’t save any streams currently running, but it won’t cause Plex to crash.
I plan to add more predictive caching features, but this is the first usable version. It has NO dependencies on Plex, it infers everything from filesystem syscalls at the moment.
I hope someone gets some use from this! I would love some feedback on what features I could add and bugs that need to be squashed. This is very much in beta and kind of a weekend project, so there are probably a few bugs to work out. I don’t plan on making this for Windows yet, since there’s really nothing like FUSE on Windows natively.
Check it out here! (https://github.com/DudeCmonMan/plex-hot-cache/tree/main)
At the moment, there are only two caching strategies: On-Cache-Miss (default) and Rolling Buffer. On-Cache-Miss only tops up when you run out of buffered episodes and is the default because it is very simple and “just works”, rolling buffer keeps the cache topped up by n episodes as long as you’re in the maintenance period (also very useful).
For those of you interested in my power savings journey
For those of you interested in power savings. I enabled IDLE_C states on my hard drives and am planning to sleep my drives overnight when there is little to no activity. The power savings I get from doing this greatly outweighs the increased mechanical stress (really not that much for enterprise grade drives). For some context: if you save 100W from idling / sleeping your drives 8 hours a day, 0.8kWh a day, 292kWh per year, $110.96 per year at CA $0.38 kwh prices (which by the way is absolutely ridiculous and basically robbery for an essential utility). That’s enough savings to buy you a refurb hdd every year - from sleeping ALONE.
I used to be a very “high-performance” “go fast” type of person, but as I grew older, I realized that low power and efficiency was really the big win. Enabling C-States, maintenance periods, smart caching, etc. have reduced my power consumption by hundreds of Watts and have probably saved me hundreds of dollars over the last few years. Of course a lot of this is enabled by advancements in the industry, so I am infinitely thankful for that.
A bit of background for myself, I’m a Software Engineer with a background in hardware and embedded systems, so this kind of stuff is fun for me. The work I do for my career and my hobbies are directly aligned, I am blessed that I find comfort in messing with servers.
I generally write in Python, but I’ve recently moved to Rust and will probably be using Rust completely going forward. It’s good to back to compiled binaries. I’ve come full circle from C++ as my “native language” to C#, to Python, even VBA, now back to a compiled language Rust. Being language agnostic is great, especially in the age of AI.