How could I set Plex's Transcoder Temporary Directory to point to a ram based filesystem?

  • First: Plex is really amazing! It worked so seamlessly as I would have never imagined. Matched almost all content so fast, fetches the image assets so fast, auto discovery of content is near instant. Great library and playback UX! It is really an amazingly good software product!


    I want to be sure that my OMV NAS which runs Plex only spins up when Plex serves users or during the nightly maintenance timeslot or when I drop new content and it auto-discovers it. Other than that I prefer the NAS to be idle and silent, the HDD spun down. And additionally want to avoid bottlenecks or unnecessary wear leveling only due to possibly ill conceived config.



    With fatrace I monitored filesystem I/O during different Plex activity phases:

    1. idle not serving any users (I expect zero I/O of Plex unless when in the maintenance time slots)
    2. serving users browsing the library
    3. while direct playback
    4. while playback with transcoding (I hoped this is done entirely in RAM, but it actually goes through persistent storage)



    I discovered these circumstances:

    • [Solved] HDD was spinning 24/7 although I had set Plex to not keep a log.
      • Plex > Menu > Settings > Settings > General:
        • Enable Plex Media Server verbose logging
        • Enable Plex Media Server debug logging
        • Disable both.
        • Save.
      • But in comparison to other settings which are effective immediately after clicking save, that setting needs a restart to be effective!
      • After that shut down the container. And then restart the container.
      • From the next launch on, Plex was silent and really stopped the logging permanently.
    • [Open] Docker's /config/tmp-transcoding/ shall point to a directory in OMV which shall be a ramdisk (folder2ram) to speed things up and avoid HDD or SD-card wearing


      • My docker compose file maps my "Plex" share to the container's internal filepath "/config"
      • So the docker-container's /config/ is bound to /srv/dev-disk-by-uuid-DISK-UID/Plex/ which I refer to as PLEX-CONFIG-ROOT.
      • Plex > Menu > Settings > Settings > Transcoder:
        • Transcoder temporary directory:
          • By default this is empty and it is then effectively: PLEX-CONFIG-ROOT/Library/Application Support/Plex Media Server/Cache/Transcode/
          • I set it to "/config/tmp-tc/" so then the transcoding root effectively is at PLEX-CONFIG-ROOT/tmp-tc/Transcode/
          • Beware that if you set it to "/" you set it to the root of that docker container, and that leaves whereever you defined your docker containers to life.
          • All these are not speculations but observations from monitoring with fatrace.
        • Transcoder temporary directory:
          • What value causes what absolute filepaths to be written to, stated twice for better readability and SEO
          • Schematically with the the VARIABLE PARTS IN UPPERCASE
          • Concrete sample path


    Transcoding session directory

    /Transcoder Temporary Directory ROOT/Transcode/Sessions/session-id/


    init-stream0.m4s

    init-stream1.m4s


    chunk-stream0-00001.m4s

    chunk-stream0-00002.m4s

    chunk-stream0-00003.m4s

    chunk-stream0-00004.m4s.tmp


    chunk-stream1-00001.m4s

    chunk-stream1-00002.m4s

    chunk-stream1-00003.m4s

    chunk-stream1-00004.m4s.tmp



    New fragments get constantly added during playback.

    .tmp suffix while they get created. Then with the eventual file suffix.

    I never saw old ones getting deleted while playback of the corresponding movie was ongoing (but maybe that happens after a certain treshhold)

    Anyway, as soon as you stop playback, the entire session folder is deleted instantly.


    Now my question

    • If Plex for these temporary on-the-fly transcoding fragments has mechanisms to limit them in number and/or storage, and this is well within the limitations of a ramdisk (on your given system) then, I'd only need to know wat's the proper way on OMV6 to set up a RAM backed FS and point it there. And I am done. No need to sync this back to persistent storage. This is really only session data which can get discarded.
    • If Plex has no method to keep this limited, one might run into the issue of the ramdisk overflowing…
      • Then we would need a helper script which detects new session-folders within the "Transcoder temporary directory" and there always deletes a certain amount of fragments with elder timestamps or smaller numbers. Should not be too hard.
      • Question is if Plex would crash already alone by this, or only if you would rewind, and the played then being puzzled that it cannot serve the fragments, as they have been pulled away.
      • And then, would it crash, or be robust enough to regenerate.
    • I am willing to experiment and see whether I run into these crashes or not, if you guys could give me some pointers how to properly set up a ramdisk for temporary/caching directories for docker applications in general.

    Odroid HC2 - Armbian 24 Bookworm - OMV7

    6 Mal editiert, zuletzt von porg ()

  • porg

    Hat den Titel des Themas von „Is the Plex transcoder hitting the disk or only RAM ?“ zu „How could I set Plex's Transcoder Temporary Directory to point to a ramdisk filesystem?“ geändert.
  • 👍 A very good general tutorial! Note: Still I'd appreciate safe OMV-specific instructions.


    On OMV6:

    /dev/shm/

    This default mount point for the RAMdisk based FS exists in OMV6.

    I wrote a small text file there. Worked.


    /etc/fstab
    tmpfs /tmp tmpfs defaults,nosuid 0 0


    So it has no concrete "size" parameter defined. How is that decided then?

    Dynamically? Who governs these quotas?


    Also on OMV6 folder2ram is installed by the default, which primarily is there to protect your SD card from unnecessary wear leveling.

    You see that at Menu > Services > Flashmemory.

    It has no options. Only a button "Sync all". I assume that means "Sync all files which are in the RAM FS to the persistent storage".


    I'm afraid that if I let Plex write simply to /dev/shm/ without any quotas in place that this may take "space" away which is needed for the SD card auxillary space. Or if I mess with the tmpfs config in /etc/fstab that this may also render the primary SD wear leveling protection moot.


    I'd like to have a method, which is guaranteed not interfering with folder2ram or any other such mechanisms OMV may have, where I define a limited amount of RAM to be mounted at a specific mount point, which I map so that it get's available to Plex's docker container, and then point Plex there to use it as its temporary transcoding dir.


    And the good news from the great tutorial you referenced:

    Zitat

    Plex keeps these chunks around even after they have been watched, until the playback stops (pausing is not stopping, and a paused video will keep the chunks around indefinitely) or until the transcode folder drops to less than 100MB of free space. Plex has some intelligence baked in that should remove the oldest watched chunks once the free space drops to 100MB, but if that can’t keep up, you can get the dreaded “Playback Error Conversion failed” error when you try to start playback.


    Again the RAM FS must report some concrete size limitation back to Plex, for the mechanism to work.

    Odroid HC2 - Armbian 24 Bookworm - OMV7

  • @kumy pinging you as you are a contributor to the folder2ram project:

    Maybe you can tell what's a safe useage of a limited ram-rs (as a temporary directory like the Plex on the fly transcoding directory) which does not conflict with folder2ram.

    Odroid HC2 - Armbian 24 Bookworm - OMV7

  • porg

    Hat das Label OMV 6.x hinzugefügt.
  • porg

    Hat den Titel des Themas von „How could I set Plex's Transcoder Temporary Directory to point to a ramdisk filesystem?“ zu „How could I set Plex's Transcoder Temporary Directory to point to a ram based filesystem?“ geändert.
  • Successfully configured Plex to use /tmp of host which is a tmpfs (living in RAM)

    OMV comes with /tmp being configured as a tmpfs, which is a filesystem living in RAM (with swap) which is limited in size to a maximum of 50% of the RAM by default.


    $ df -h on an Odroid HC2 with 2GB of RAM with no tweaks of /etc/fstab so far returns this:


    • So in the docker compose file at the "volumes" section I just created one more binding "/tmp:/tmpfs-host"
    • And in Plex at: Settings Menu (wrench icon on the top right) > section "Settings" > Transcoder
      • I set "Transcoder temporary directory" to "/tmpfs-host"
    • From then on when playing back videos which require transcoding, fatrace showed no more corresponding I/O, as access to the special tmpfs is not registered by it. Positive confirmation! From then on during playback of files with transcoding I only saw:
      • read operations on the original video file
      • and read/write hits all the time to its database whenever I start/stop (I assume it then updates "video X played until hh:mm:ss" in the database)
    • I integrated this new experiences into my guide:
      How to install Plex on OMV6 with docker image linuxserver/plex + On the fly transcoding files only in tmpfs (living on RAM not HDD)


    This is what happens during Plex playback now on tmpfs (in RAM)


    This is what happens during Plex playback now on the HDD

    On Playback start it loads the necessary codecs:



    And from then only the read access to the movie file and read/write to the DB

    In the DB it notes where your playback currently is: in regular intervals every few secs, or instantly when you pause/resume.

    I mean that's still a bit of an unnecessary I/O, but as the disk is spinning anyhow to read the movie, that few bytes of write every sec to the spinning HDD should not pose a problem long time I hope.


    Odroid HC2 - Armbian 24 Bookworm - OMV7

    Einmal editiert, zuletzt von porg ()

  • porg

    Hat das Label gelöst hinzugefügt.
  • To get your own and size limited tmpfs

    1. Edit /etc/fstab like this

    Zitat
    Code
    UUID=dede0252-4d2a-4b10-8320-063fc4c949a2       /   ext4    noatime,nodiratime,defaults,commit=600,errors=remount-ro    0 1
    tmpfs /tmp tmpfs defaults,nosuid 0 0
    tmpfs /tmp-plex tmpfs defaults,nosuid,size=256m  0 0  # Other than the size parameter just like /tmp
    # >>> [openmediavault]
    /dev/disk/by-uuid/f0233da3-473e-450d-9a18-b2ae254fc439      /srv/dev-disk-by-uuid-f0233da3-473e-450d-9a18-b2ae254fc439  ext4    defaults,nofail,user_xattr,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0,acl 0 2
    # <<< [openmediavault]


    2. In the docker file I then bound the host's /tmp-plex to dockers internal path /tmpfs-host-plex

    3. And in Plex I set the Transcoder Temporary Directory to /tmpfs-host-plex


    Also worked. Plex then wrote there.


    Benefits:

    • Now you are sure no-one else on the host uses this special temporary directory.
    • And you can limit it in size and see what difference that makes. Never go above the recommended max of 50% of your RAM though!

    Odroid HC2 - Armbian 24 Bookworm - OMV7

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!