Search code examples
apachecachingxampphttp-live-streaming

How to get Apache to cache video files in memory?


I'm hosting an HLS stream with XAMPP / Apache, which basically means I have a folder in my document root that contains a couple of incrementally numbered 10-second video files.

Every 10 seconds, a new video file is saved into the folder and the oldest video file in the folder is deleted.

Apart from these video files, the document root also contains some other files, such as PHP scripts and playlist files.

My server has plenty of RAM and a pretty fast CPU, but is using a comparatively slow hard disk.

Given the fact that the constant downloading of these video files is likely what's going to make or break the server performance, it seems like a good idea to cache these files in memory.


If Apache were to keep all video files (with a .ts extension) that're downloaded by a user's video player, in it's memory for about 60 seconds, the next user would then be able to download the file much faster. Apache could rely on the files not changing after the first open and on the fact that the files won't be requested anymore after those 60 seconds.

All other files do not (necessarily) have to be cached, since they're rather small and are regularly modified.

Is anyone able to give me directions on how to get started?


Solution

  • Modern operating systems already cache accessed files in memory. The whole process is managed by the kernel automatically.

    Apache in-memory caching won't help you since it needs all the files at start-up.

    If you want some level of control over the caching you could use vmtouch. Check the manual.