Optimising Plex Media Server

Plex Media Server is an amazing piece of free software that allows you to basically run your own Netflix.

Plex will scan folders for media, detect what the movie or show is and present it to you in a very nice library. It also has the ability to transcode video which allows you to watch it on all sorts of devices, regardless of the format the video is in. While these features can be a good thing, they can also consume a lot of resources which is definitely not ideal when running in a shared environment such as a HostDoc VPS.

This guide will show you how to optimize your Plex Media Server so that you can still enjoy the benefits that Plex has to offer, while also being a “good neighbor” on the shared server, or VPS.

Transcoding

The first and foremost tweak we can make to Plex is to change some settings that makes Plex use less resources while transcoding.

It would be a shame for me to not point out the most obvious thing, which is that in most cases you may not even need to transcode in the first place! If you are watching your media through the Plex web interface, the most basic thing you can do is to set the playback quality in the player.

5

In the image above, you can see the Playback Settings menu (the 3 sliders, 3rd icon from the right) and the Quality selected is “Original”

Setting the quality to “original” means that the video is being directly streamed without any transcoding, which is the single most effective way to reduce resource use.

If you require transcoding, for example because of your internet connection or the file isn’t playable directly, then we can still make Plex transcode use less resources.

4

In the Plex settings, under Transcode, you will be able to set some options that will definitely help.

The image above is an example of some good settings to use. I’ll explain them.

“Prefer higher speed encoding” means that the CPU will spend less time, or resources, on the actual quality of the video which means that it can complete each block of video without stress. The opposite end of this spectrum, “Make my CPU hurt” means that the CPU will be pushed VERY hard to produce the highest quality output, which means that your resource usage would be unfair for a shared environment like a VPS. Don’t be a noisy neighbor, prefer higher speed encoding.

The other settings, such as the buffer can be left at the default of 60 seconds. This means that it will transcode 60 seconds of video, and then rest, transcode another 60 seconds and rest again and so on. Setting this higher will give you more bursts of CPU usage, less frequently, setting it lower will create more CPU usage as well as accessing the disk more frequently.

Max simultaneous transcodes is best left at 1, unless you have a good reason to allow more, such as you have more than one XBOX or set top box that cannot play directly, which is often the case. Change it off unlimited, just in case.

Library scanning

Library scanning is another important area that we can improve resource usage in. Plex will, by default, want to scan each file and really look into the contents of it, which is in most cases highly unnecessary and just uses more precious resources!

In the Plex settings, under Library, we can make the following changes:

3

If your settings look like the screenshot above, you’ve saved a lot of resources!

Automatically scanning the file system for changes can be buggy due to the use of inotify, especially if you’re mounting a network storage for your media. It consumes more resources than is needed, turn it off.

Periodic scanning is the best way to scan your files in. Daily is the best option of course, but you can lower this without too much of an impact due to the fact that we are going to make more tweaks with the generation of thumbnails, etc.

Emptying trash on every scan is usually not needed, so turn that off also.

Generating thumbnails and analyzing audio consume a ton of resources, and there’s no real benefit. Unless you explicitly need those things, for the sake of resource usage, set them to “never”

Scheduled tasks

Plex will schedule some tasks that by default can be quite consuming of resources, mainly CPU and disk access (I/O)

2

First you can see the time that the tasks will be scheduled to run are usually when I’m asleep, adjust those to the times where there will likely be nobody watching anything. If these run while you are transcoding, for example, your resource usage will be higher than it should be and will make you a noisy neighbor and that’s a bad thing!

Backup database every three days
Optimize database every week
Remove old bundles every week
Remove old cache files every week
Refresh local metadata every three days
Perform refresh of program guide data.

Those things happen once every few days to a week, which isn’t really a huge problem. Backups and optimizing aren’t the end of the world, neither is a quick grab of guide data off the internet once a day

Update all libraries during maintenance
Upgrade media analysis during maintenance
Refresh metadata periodically
Perform extensive media analysis during maintenance

The above things do not need to be done daily, updating libraries is done already in the Library settings as often as you’ve chosen already. Media analysis and metadata refresh are 2 things that don’t need to be done daily. Extensive media analysis is an absolute waste of resources, we really don’t need to have it extensively look at every movie every single day, it’s not likely to ever change and it’s a complete waste.

Trimming the fat

By default, Plex comes with the DLNA server turned on - which is great if you are running Plex at home on a home network, but it’s horrible for security reasons and good neighborly behaviour to not scream all the time to your neighbors.

1

Turn it off, it’s not going to do you any good when it’s running on a VPS. DLNA doesn’t work remotely anyway, and it’s just going to create a lot of noise advertising itself to not only other VPS on your node, but everything on that subnet, in that datacenter. It’s horrible. Just turn it off unless you really know what you’re doing and have a crazy reason for needing it enabled (which, by the way, I’d love to hear about!)

Conclusion

If you’ve made it this far, awesome! You’ve just saved yourself from getting suspended for using too much resources on your VPS, and you’re being a good neighbor. You also get the benefit of your VPS being much faster, and your Plex experience will be better. You will sleep better at night knowing that you’re doing the right thing.

Please comment below if you have anything you’d like to add to this, all feedback is appreciated!

For some fun, can you guess which movie I was playing in the first screenshot?

Thanks for this comprehensive guide.

Just curious on setting up PLEX with a few users:

Would 1 transcoding thread suffice? How does it affect users experience when skipping through the video.

Say my current VPS is 3 vcores, is it safe to put 3 transcoding threads?

cybertech wrote:

Thanks for this comprehensive guide.

Just curious on setting up PLEX with a few users:

Would 1 transcoding thread suffice? How does it affect users experience when skipping through the video.

Say my current VPS is 3 vcores, is it safe to put 3 transcoding threads?

Excellent question. My advice would be to use 1 transcode per thread in your situation, but keep a close eye on the resource usage in htop.

Ideally, you shouldn’t exceed 25% CPU usage for any longer than an hour, just to be a good neighbor on your node. The best way to keep things in check would be to not transcode unless necessary. I would probably need to get clarification from the Doc on whether that limit is per core or overall, but my assumption would be that it’s per core. If you have an hourly load average of under 2.25 then you’re within the limits.

As for skipping through the video, that will always restart the transcoder (since it will transcode in 60 second blocks)

I would suggest to test it out, open up 3 Plex tabs and play 3 different videos at a time with the transcoder running (ie anything other than “original” quality) and watch htop and check for any buffering or high usage.

I hope that helps

David wrote:

cybertech wrote:

Thanks for this comprehensive guide.

Just curious on setting up PLEX with a few users:

Would 1 transcoding thread suffice? How does it affect users experience when skipping through the video.

Say my current VPS is 3 vcores, is it safe to put 3 transcoding threads?

Excellent question. My advice would be to use 1 transcode per thread in your situation, but keep a close eye on the resource usage in htop.

Ideally, you shouldn’t exceed 25% CPU usage for any longer than an hour, just to be a good neighbor on your node. The best way to keep things in check would be to not transcode unless necessary. I would probably need to get clarification from the Doc on whether that limit is per core or overall, but my assumption would be that it’s per core. If you have an hourly load average of under 2.25 then you’re within the limits.

As for skipping through the video, that will always restart the transcoder (since it will transcode in 60 second blocks)

I would suggest to test it out, open up 3 Plex tabs and play 3 different videos at a time with the transcoder running (ie anything other than “original” quality) and watch htop and check for any buffering or high usage.

I hope that helps

Yes indeed we are here in such discussions so as not to cause any trouble

Sounds good to test it out using tabs

cybertech wrote:

Yes indeed we are here in such discussions so as not to cause any trouble

Sounds good to test it out using tabs

Please let me know how you go, and if there’s anything I could improve in the guide to make it easier to follow.

For clarification, you are allocated a maximum of 25% of a physical core with the ability to burst to 100% for 1 hour in any 24 hour period.

This means that with 3vCores, you effectively have an allocation of 75% of the physical core and can burst up to 300% for up to an hour in any given 24 hour period.

If you are monitored using anything over 300% e.g 301%, your instance is killed. If you burst for more than an hour, your instance is killed.

It is important to highlight the initial kill is not a suspension and you can power back up when you want.
If the same VM is caught using more than their fair share again, a 24 hour suspension is put in place. A third time 7 day suspension.
The fourth is the last chance and all machines under the account will be terminated.

We are rather laxed and understanding. Communication is key.
Let us know if you have issues controlling your load or your applications are running wild or you suspect you have been compromised so you are not penalised.

Thanks for clarification doc.

I must admit my lack of understanding on the allocation. Or Linux in general

Kindly correct me on below assumptions using load from top:
For 3 vcores the allocation is load of 2.25 (75%)
For 3 vcores burst is allowed 3.00 up to an hour within 24h
For 3 vcores if monitored to be using more than 3.00 or bursting more than an hour, it is powered down.

Precisely because doc is understanding, makes clients like me want to be even more accommodating

Anyway htop looks way better than top haha.

That’s correct. It ensures that everyone gets a fair service and allows for bursting where needed, within reason. Think of a scale of $/CPU time. With $$$$$ for dedicated servers and $ for VPS, it’s proportional

how do you normally upload into the server?

cybertech wrote:

how do you normally upload into the server?

I really want to answer that, but I would be admitting to torrenting if I did

If you do, make sure you only set transmission to download 1 file at a time with a max of 10 peers, and set upload speed to 0 and NEVER seed.

Otherwise, you could upload the files with SFTP/SSH or even rsync from a seedbox if you have one. So many options really

David wrote:

cybertech wrote:

how do you normally upload into the server?

I really want to answer that, but I would be admitting to torrenting if I did

If you do, make sure you only set transmission to download 1 file at a time with a max of 10 peers, and set upload speed to 0 and NEVER seed.

Otherwise, you could upload the files with SFTP/SSH or even rsync from a seedbox if you have one. So many options really

Was curious because uploading via SSH is slow. Anyhow will try FTP first.

(Psst…Torrenting is allowed??)

cybertech wrote:

David wrote:

cybertech wrote:

how do you normally upload into the server?

I really want to answer that, but I would be admitting to torrenting if I did

If you do, make sure you only set transmission to download 1 file at a time with a max of 10 peers, and set upload speed to 0 and NEVER seed.

Otherwise, you could upload the files with SFTP/SSH or even rsync from a seedbox if you have one. So many options really

Was curious because uploading via SSH is slow. Anyhow will try FTP first.

(Psst…Torrenting is allowed??)

So many options indeed

“Torrenting isn’t allowed”… meaning don’t attract attention, don’t download too many torrents at once (it can have a negative impact on the network and disk IO) and don’t attract DMCA notices and you’ll be fine. It’s kinda like having a bit party at your house, if you keep it quiet enough and still have a good time, the neighbours won’t get angry and call the police

But yeah, “no torrenting”

Right. Seedbox I do have. It’s much to learn but at least it’s in the “cloud”

cybertech wrote:

Right. Seedbox I do have. It's much to learn but at least it's in the "cloud"

If you have a seedbox, you can let that do the “dirty work” (download the torrents) and either use rsync to sync those files to your VPS, or you could use sshfs to mount the seedbox as a directory on your VPS.

What is the ping from your VPS to your seedbox?

David wrote:

cybertech wrote:

    Right. Seedbox I do have. It's much to learn but at least it's in the "cloud"

If you have a seedbox, you can let that do the "dirty work" (download the torrents) and either use rsync to sync those files to your VPS, or you could use sshfs to mount the seedbox as a directory on your VPS.

What is the ping from your VPS to your seedbox?

sshfs sounds very interesting. Ping is around 300ms. Maybe won’t work well?

Hmm, 300ms is on the higher end. It would technically work, but as you mentioned, it might not work well.

In that case, I’d look at either using a scheduled rsync to copy the media across, or just torrent locally on your Plex server - but as I mentioned before, you must be careful to have it set up to not seed, to not upload and to have a max of 10 peers all up to keep things friendly for all

Just some observations / assumptions:

  • maybe number of transcoding threads does not have big impact unless using multicores (4+) and/or dedicated. As long as transcoding is required, CPU usage is pretty high
  • subtitles use alot of CPU power , it is considered “transcoding”.
  • found 4vcores to be best in terms of keeping load low ~2.00ish (friendly neighbor), and 3vcores to be quite sufficient within AUP. Considering direct play @1080p + .SRT

without subtitles any core goes really. But I need my English badly otherwise comprehension is affected

Due to my ISP limiting non https uploads to Plex box, added owncloud+https. It works but somehow feels not well put together.