Plex: Guide to Moving Transcoding to RAM


Recommended Posts

2 hours ago, amplified2000 said:

Ok, I got it working.. after looking at your initial response Hoopster I realized my mistake.. i set a path in the container from /transcode to /tmp/PlexRamScratch and then set Key 1 to /transcode as well as the Plex Server Temp Dir to /transcode and it seems to be working.

And I just noticed you had TRANS_DIR defined as a variable.  It should be a path.  But it looks like you may have it sorted.

Link to comment
  • 1 month later...

Started getting some notices today when I had a few people streaming that my docker utilization was high (75%). Checked with docker system df -v what was high in usage and noticed Plex was around 10gb. Thinking of either moving it to RAM or an unassigned SSD, but wanted to see if my config looked right first.

Plex settings is /transcode
Docker below
image.thumb.png.5e238010d69703a6a39da1c7dedd9139.png

Edited by KJThaDon
Link to comment
On 5/18/2020 at 1:31 AM, KJThaDon said:

Started getting some notices today when I had a few people streaming that my docker utilization was high (75%). Checked with docker system df -v what was high in usage and noticed Plex was around 10gb. Thinking of either moving it to RAM or an unassigned SSD, but wanted to see if my config looked right first.

Plex settings is /transcode
Docker below
image.thumb.png.5e238010d69703a6a39da1c7dedd9139.png

Your problem may be due to the /transcode path not being something like /tmp if you wanted to transcode to ram or /tmp/PlexRamScratch if you use the size limited ram disk script as posted earlier in the thread. Since /transcode does not exist as a an actual directory in your setup most likely, I believe Plex is defaulting to transcoding within the docker image and that is why it is filling up.

Link to comment
  • 2 months later...

I just test this and noticed a big impact in transcoding performance. Also, I have around 20 dockers. I was hitting my SSD IO pretty hard, every time I added or modified a large quantity of media, also messing with VMs. This should ease up things a bit. 

 

Got 32gb ram good stuff

Link to comment
  • 1 month later...

I wanted to know which tmpfs (ramdisks) exist by default and which size they have:

df -h
Filesystem      Size  Used Avail Use% Mounted on
rootfs           16G  764M   15G   5% /
tmpfs            32M  292K   32M   1% /run
devtmpfs         16G     0   16G   0% /dev
tmpfs            16G     0   16G   0% /dev/shm
cgroup_root     8.0M     0  8.0M   0% /sys/fs/cgroup
tmpfs           128M  628K  128M   1% /var/log
/dev/sda1        15G  254M   14G   2% /boot
/dev/loop0      9.2M  9.2M     0 100% /lib/modules
/dev/loop1      7.3M  7.3M     0 100% /lib/firmware
/dev/md1         11T  9.9T  1.1T  91% /mnt/disk1
/dev/md2         11T   11T  809G  93% /mnt/disk2
/dev/md3         11T  9.9T  1.1T  91% /mnt/disk3
/dev/md4         11T  9.9T  1.1T  91% /mnt/disk4
/dev/md5         11T  9.9T  1.1T  91% /mnt/disk5
/dev/md6         11T  7.7T  3.3T  71% /mnt/disk6
/dev/md7         11T  5.0T  6.0T  46% /mnt/disk7
/dev/md8         11T  2.7T  8.3T  25% /mnt/disk8
/dev/md9         11T  7.4T  3.6T  68% /mnt/disk9
/dev/nvme0n1p1  932G  234G  698G  26% /mnt/cache
shfs             99T   73T   26T  74% /mnt/user0
shfs            100T   73T   27T  74% /mnt/user
/dev/loop2       20G  1.1G   19G   6% /var/lib/docker

The main reason was to check how much size is set for /dev/shm as some people in the plex forums use this as transcoding path combined with this command:

mount -o remount,size=8G /dev/shm

As I have installed 32G RAM it seems that /dev/shm is limited to the size of my 16GB USB flash drive, correct? By that it would be possible to use /dev/shm/PlexRamScratch without the need of an additional script. What do you think? EDIT: After reading some websites I would say its not save to use /dev/shm as its the default shared memory in linux and not cleaned up by default. This means if other applications use this memory and its full because of Plex, this could result in performance problems or errors for other applications. So its better to use /tmp/PlexRamScratch as this would be an exclusive ramdisk for Plex alone.

 

Does anyone know why most people suggest 4GB? I mean why isn't it 1GB or 8GB?

Edited by mgutt
Link to comment

Yesterday, I was lazy and set only "/dev/shm/plextranscode" as my transcoding path. I checked the path and it was created:

ls /dev/shm
plextranscode/

 

But it stays empty while transcoding!

 

I saw in the Main overview of the Unraid WebGUI that it still produces writes on the NVMe where the docker image is located. With this useful command I was able to verify it:

inotifywait -mr /mnt/cache

1212771672_2020-09-1912_39_05.png.c6311a148b2615ce6f8b71e0a3af541b.png

 

While this returned nothing:

inotifywait -mr /dev/shm

So the writes are not leaving the docker image. But why? The container's config looks correct:

1941782839_2020-09-1912_46_36.png.0b0639510484930a9862e59a9f8074ac.png

 

I opened the plex container's console and tried to find the path and yes its writing to a complete different path:

# ls -l /tmp/Transcode/Sessions
total 0
drwxr-xr-x 1 plex users 62522 Sep 19 12:49 plex-transcode-b7dnev7r0gdgfjq8267pwoxu-136bae98-3ca4-4cbc-ad26-3656b6830885
# ls -l /tmp/Transcode/Sessions
total 0
drwxr-xr-x 1 plex users 62890 Sep 19 12:50 plex-transcode-b7dnev7r0gdgfjq8267pwoxu-136bae98-3ca4-4cbc-ad26-3656b6830885
# 

I verified if the container is able to write a file into /transcode

# echo "test" > /transcode/test.txt
# cat /transcode/test.txt
test
# ls -l /transcode/test.txt
-rw-r--r-- 1 root root 5 Sep 19 12:51 /transcode/test.txt

Re-checked if it exists in dev/shm:

ls /dev/shm/plextranscode
test.txt

Strange. Re-checked plex transcoding path and its correct:

1210902106_2020-09-1912_52_56.png.7517c949b688da599a30ca8942104c93.png

 

Double-checked the Preferences.xml content:

1529389671_2020-09-1912_55_53.png.e27cc7cbdb5370a7362b32577b865f26.png

 

Why is Plex writing to a different folder... hmmm. Maybe a chmod thing? Let's check the auth:

ls -l

...

drwxrwxrwt   1 root root   132 Sep 19 04:14 tmp
drwxr-xr-x   2 root root    60 Sep 19 12:51 transcode

I chmod them to 777:

chmod -R 777 /dev/shm/plextranscode
root@Thoth:~# ls -l /dev/shm
total 0
drwxrwxrwx 2 root root 60 Sep 19 12:51 plextranscode/

Check if its inside the docker container active and it looks good:

ls -l

drwxrwxrwt   1 root root   132 Sep 19 04:14 tmp
drwxrwxrwx   2 root root    60 Sep 19 12:51 transcode

...

# ls -l /transcode
total 4
-rwxrwxrwx 1 root root 5 Sep 19 12:51 test.txt

So I restart the plex container and started a different movie... aahh looks nice:

inotifywait -mr /dev/shm

/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ ACCESS init-stream1.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ ACCESS chunk-stream1-00080.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CLOSE_NOWRITE,CLOSE init-stream1.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CLOSE_NOWRITE,CLOSE chunk-stream1-00080.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ OPEN init-stream0.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ OPEN chunk-stream0-00081.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ ACCESS init-stream0.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ ACCESS chunk-stream0-00081.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CLOSE_NOWRITE,CLOSE init-stream0.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CLOSE_NOWRITE,CLOSE chunk-stream0-00081.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ OPEN init-stream1.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ OPEN chunk-stream1-00081.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ ACCESS init-stream1.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ ACCESS chunk-stream1-00081.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CLOSE_NOWRITE,CLOSE init-stream1.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CLOSE_NOWRITE,CLOSE chunk-stream1-00081.m4s
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ CREATE chunk-stream1-00143.m4s.tmp
/dev/shm/plextranscode/Transcode/Sessions/plex-transcode-08xmsae9kwytrf1u91lnijt0-d3df683f-e543-49bc-8f22-7ff29640ead4/ OPEN chunk-stream1-00143.m4s.tmp

Conclusion:

If you use a different path than /tmp (which is already chmod 777) f.e. a subfolder inside of /tmp you need to set chmod 777 to it, else it won't work!


 

Edited by mgutt
  • Like 3
  • Thanks 1
Link to comment

By this guide Plex uses your RAM while transcoding which prevents wearing out your SSD.

 

Edit the Plex Container and enable the "Advanced View":

1340471342_2021-02-0111_29_39.png.01cb772114f1375fe10164c69e11a197.png

 

Add this to "Extra Parameters" and hit "Apply":

--mount type=tmpfs,destination=/tmp,tmpfs-size=4000000000

Result:

2090760801_2021-02-0116_53_16.png.d6593aa0dab6835b74a5fb8ffc3a89ee.png

 

Side note: If you dislike permanent writes to your SSD add " --no-healthcheck ", too.

 

Now open Plex -> Settings -> Transcoder and change the path to "/tmp":

1892807613_2021-02-0116_56_03.png.17c3c525c5cfa3218220dba587764d61.png

 

If you like to verify it's working, you can open the Plex containers Console:

341988375_2021-02-0111_38_32.png.5a59b24c54fc18f7d7681a2686c7ad6f.png

 

Now enter this command while a transcoding is running:

df -h

 

Transcoding to RAM-Disk works if "Use%" of /tmp is not "0%":

Filesystem      Size  Used Avail Use% Mounted on
tmpfs           3.8G  193M  3.7G   5% /tmp

 

After some time it fills up to nearly 100%:

tmpfs           3.8G  3.7G  164M  97% /tmp

 

And then Plex purges the folder automatically:

tmpfs           3.8G  1.3G  3.5G  33% /tmp

 

If you stop the movie Plex will delete everything:

tmpfs           3.8G  3.8G  0  0% /tmp

 

By this method Plex never uses more than 4GB RAM, which is important, as fully utilizing your RAM can cause an unexpected server behaviour.

 

  • Like 11
  • Thanks 8
Link to comment
  • 4 weeks later...
13 minutes ago, SPOautos said:

can I still just follow the instructions on the very first original post?

Yes, still works.  At least it did for me a couple of months ago.  I am now using the tmpfs/scratch disk method.

 

Of course, Plex Pass is required but that is not mentioned in first post.

 

You also want to select these options in the Transcoder settings:

image.thumb.png.c33bc0f2f901e411515a3e995fccc284.png

Link to comment
32 minutes ago, Hoopster said:

Yes, still works.  At least it did for me a couple of months ago.  I am now using the tmpfs/scratch disk method.

 

Of course, Plex Pass is required but that is not mentioned in first post.

 

You also want to select these options in the Transcoder settings:

image.thumb.png.c33bc0f2f901e411515a3e995fccc284.png

 

Did you switch to the tmpfs/scratch disk method because you were having issues? Was Plex using up all your ram? I have 32GB of ram but I've never seen my ram utilization get over around 7-8Gb so I feel like I have plenty of headway.

 

 

Edited by SPOautos
Link to comment
1 minute ago, SPOautos said:

Did you switch to the tmpfs/scratch disk method because you were having issues? Was Plex using up all your ram? I have 32GB of ram but I've never seen my ram utilization get over around 7-8Gb so I feel like I have plenty of headway.

In addition to transcoding movies as they stream, I am running OTA TV show recording through Plex via a couple of HDHomeRun tuners.  A recent change in HDHomeRun recording started using 16GB per 1-hour program.  When I had two records going at once, the 2nd would fail as I only had 32 GB RAM. 

 

The HDHomeRun change was to enable time-shifting while recording.  Since I never watch a recording in progress, I saw no need to use that much RAM.

 

I also now have 64GB RAM so it likely would not matter as much.

Link to comment
6 minutes ago, Hoopster said:

In addition to transcoding movies as they stream, I am running OTA TV show recording through Plex via a couple of HDHomeRun tuners.  A recent change in HDHomeRun recording started using 16GB per 1-hour program.  When I had two records going at once, the 2nd would fail as I only had 32 GB RAM. 

 

The HDHomeRun change was to enable time-shifting while recording.  Since I never watch a recording in progress, I saw no need to use that much RAM.

 

I also now have 64GB RAM so it likely would not matter as much.

 

Well, I am fixing to set up a HD Homerun OTA tuner with Plex but we mostly use it for live viewing of bad weather and such. I suppose if we decide to start recording things I'll need to change it. 

 

So when you record with HD Homerun does it put the entire recording temporarily in the transcode folder and then move it to the HD Homerun? I thought the HD Homerun saved recordings directly on it.

 

Can you please give me a basic explanation of how tmpfs/scratch disk method resolved your issue.....just so I have a better understanding of what its doing....it sounds like I could very easily run into that issue if someone decided to start recording OTA shows.

Edited by SPOautos
Link to comment
1 minute ago, SPOautos said:

So when you record with HD Homerun does it put the entire recording temporarily in the transcode folder and then move it to the HD Homerun? I thought the HD Homerun saved recordings directly on it.

There is a version of the HDHomeRum that has its own storage.  I don't have that.  I have a couple of dual-tuner boxes with no storage.

 

Recordings go to the transcode folder and then they are post-processed to remove commercials and and end up in an unRAID TV_Shows share.

 

The good thing about running the HDHomeRun through Plex (why pay for HDHR DVR when I have a Plex Pass and can use it as the DVR?) is that I can also watch live TV from home tuners over the Internet if I don't have local TV access or prefer home local channels.

Link to comment
1 minute ago, Hoopster said:

There is a version of the HDHomeRum that has its own storage.  I don't have that.  I have a couple of dual-tuner boxes with no storage.

 

Recordings go to the transcode folder and then they are post-processed to remove commercials and and end up in an unRAID TV_Shows share.

 

The good thing about running the HDHomeRun through Plex (why pay for HDHR DVR when I have a Plex Pass and can use it as the DVR?) is that I can also watch live TV from home tuners over the Internet if I don't have local TV access or prefer home local channels.

 

How are you removing the commercials? Does Plex do that on its own when you DVR something?

 

Well since I'm doing all this right now maybe I should just go ahead and set up the tmpfs/scratch disk method. I guess I need to go back some pages and research that a bit more.

 

What is the tmpfs/scratch disk method doing that helps you be able to transcode with RAM but still do all the dvr stuff with the OTA? I guess I'm not following whats going on. I'm actually setting up a HD Homerun this week so I guess I need to understand how this is all working.

Link to comment
44 minutes ago, Hoopster said:

In addition to transcoding movies as they stream, I am running OTA TV show recording through Plex via a couple of HDHomeRun tuners.  A recent change in HDHomeRun recording started using 16GB per 1-hour program.  When I had two records going at once, the 2nd would fail as I only had 32 GB RAM. 

 

The HDHomeRun change was to enable time-shifting while recording.  Since I never watch a recording in progress, I saw no need to use that much RAM.

 

I also now have 64GB RAM so it likely would not matter as much.

 

As I understand it (or maybe dont understand it) the tmpfs/scratch disk method allows you to create a limited amount of ram for Plex to use. If you were maxing out your /tmp then how are you able to have the same functionality of having two recordings going at once that use 16GB each when you have reduced your ram allocation?  Does Plex start to overflow into a different location that isnt ram?  I'm confused about that.

Link to comment
1 minute ago, SPOautos said:

If you were maxing out your /tmp then how are you able to have the same functionality of having two recordings going at once that use 16GB each when you have reduced your ram allocation?

See the 2nd setting above; Convert while recording.  Otherwise I would run out.  I have allocated 16GB to the scratch disk.  Seems to be working so far.

  • Thanks 1
Link to comment

When using the tmp/PlexRamScratch method does it dedicate that space similar to how a VM does or is it more like a usage cap?  I'm thinking it will still let a VM or docker or whatever dip into that same ram space as Plex uses....but just want to verify that it will.

 

 

Edited by SPOautos
Link to comment
9 hours ago, SPOautos said:

Since I have plenty of RAM and am not worried about limiting it can I still just follow the instructions on the very first original post?

Don't do it. If you watch two 4K movies it will probably fully utilize your RAM. And some users said it will fill it also if the "optimize" feature is used or a permanent live TV is running.

8 hours ago, SPOautos said:

Does Plex start to overflow into a different location that isnt ram?

No, Plex deletes the oldest transcoding parts of a movie automatically (One movie is splitted in hundreds of parts while transcoded). Having an unlimited size means the full transcoded movie is inside the transcoding dir. If it's limited in size, Plex purges the dir and removes the oldest transcoding parts of the movie. So the disadvantage of this method is, that if you jump to the beginning of the movie, the server has to re-transcode the movie which causes depending on your transcoding performance some seconds wait time.

 

Note: Nobody says that you need to set the transcoding ramdisk to 4GB. Use 20GB if you like, but never let Plex use the total RAM. This will probably result in a server/VM/docker crash. Example (Emby killed the RAM):

https://forums.unraid.net/topic/97726-memory-usage-very-high/

 

PS Even a 500MB ramdisk should work. 4GB is the default because many people tested this value with multiple concurrent 4K transcodings. With 5 and more 4K transcodings I would suggest to raise the size to 6 or 8GB. But everything above this size is useless. Or do you permanently jump backwards through your movie?

6 hours ago, SPOautos said:

does it dedicate that space similar to how a VM does or is it more like a usage cap

It's only a cap. So if you transcode nothing, it does not utilize your RAM.

Edited by mgutt
  • Like 1
Link to comment
41 minutes ago, frodr said:

But a film lagged playing direct (116 Mb/sec)

It was directly playing and its bitrate is 116 Mbit/s?! This is extremely high, even for a 4K movie. Are you sure your Client is able to render such a high bitrate? And finally this stands in contradiction to the 19% fill rate of the "/tmp/PlexRamScratch" folder. If the movie was directly played, the folder must stay empty. Its only filled on transcoding operations.

Link to comment
2 hours ago, mgutt said:

It was directly playing and its bitrate is 116 Mbit/s?! This is extremely high, even for a 4K movie. Are you sure your Client is able to render such a high bitrate? And finally this stands in contradiction to the 19% fill rate of the "/tmp/PlexRamScratch" folder. If the movie was directly played, the folder must stay empty. Its only filled on transcoding operations.

It was not direct play.  It made transcoding to max resolution. The ramdisk picture is somewhat misleading, 19% is just after few minutes play. The film started with long stops after a few minutes, RAMdisk full? That could explain what no stops after I set transcoding to a smb ssd share. 

Link to comment
4 minutes ago, mgutt said:

19% isn't full, but maybe your system was out of RAM?! Please check while transcoding your RAM usage with "free -h". 

 

The film stopped later than when 19% was recorded. I will test again tomorrow. 128G of total mem, some 30% in use.

Edited by frodr
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.