Lots of traffic in /tmp on intro detection

Server Version#: ltest

Hey guys, for intro detection it seems there is a lot of data going in and out of the /tmp dir. 0.2-0.8G per Episode. That’s Terrabytes of data going over the SSD (in my case)
Why not restrict this to some dir inside the plexmediaserver dirstructure, Cache or Transcode comes to mind, so one could plan for it and not kill the ssd?

+1 to use the Transcode directory setting.

May I see the logs, PMS transcoder settings and any service override definitions please?

If this is something which can, and should, be subject to a different variable, I will write it up and champion it

From an operational perspective,

/tmp on linux is tmpfs which is RAMFS . It should not be touching your SSD.

Are you expressly mounting a SSD partition on /tmp ?

/tmp ist just a subdir, per default, unless it specifically mounted otherwise, which may be the case on some distributions but it’s certainly not the norm.
/ is a ssd, in my case.

Where can I look up PMS transcoder settings and service overrides you are speaking of?
I don’t think I have any.
Also which of the logs?

You’ll find TranscoderTempDirectory="pathname" in Preferences.xml if you’ve set it.

Interestingly, I just looked and there is indeed disparity between distros
It also seems I’ve been doing tmpfs for a long time

tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=8192M 0 0

Something to consider with SSDs, the noatime option saves a great deal of writing to the SSD. Linux will no longer update the last-accessed-time field of a file or directory every time you access it. That’s a lot of page writes saved in very short order.

EDIT: Here’s one user where tmpfs is the default.
image

If I look at my system, you can see the system defaults and my mount

Filesystem          1K-blocks        Used   Available Use% Mounted on
udev                 16355384           0    16355384   0% /dev
tmpfs                 3280420        2868     3277552   1% /run
/dev/nvme0n1p2      125465980    28936732    90112864  25% /
tmpfs                16402092      140464    16261628   1% /dev/shm
tmpfs                    5120           4        5116   1% /run/lock
tmpfs                16402092           0    16402092   0% /sys/fs/cgroup
tmpfs                 6291456          48     6291408   1% /tmp
/dev/nvme0n1p1         487040       24840      462200   6% /boot/efi
/dev/nvme0n1p4      807321448   409742784   397578664  51% /home
/dev/loop1              96128       96128           0 100% /snap/core/8935
/dev/loop2              96256       96256           0 100% /snap/core/9066

I looked into Preferences.xml, I have no TranscoderTempDirectory set.

I tried setting it but it only affects the transcode sessions, which go inside the plex dir per default anyways.

Can you make the intro detection/deep analyse respect this setting as well please?

p.s. The picture you posted with the default 100M /tmp directory would probably result in lots of errors with the current usage of plexmediaserver in /tmp for intro detection, which is almost 1G per episode for me and i only have 720p.
p.p.s RPI may be a bit of a special case
p.p.p.s my rpi with raspbian has no tmpfs /tmp dir

As I said above, we’re going to clean up the confusion caused in the new packaging.

Having traced it all down back to the beginning of time (2011) for Linux.

  1. TMPDIR was always used (for POSIX compliance) 0
  2. TranscoderTempDir is not set by default. If you want that, you can set in Preferences.xml or in the GUI (transcoder - show advanced)

When PMS was first ported to Linux and the team setup the variables, they made plans for having all nice names. PLEX_MEDIA_SERVER_TEMPDIR was supposed to be included.

In the initial start_pms script, it was used, if defined, by

TMPDIR="$PLEX_MEDIA_SERVER_TMPDIR"

The transition from SYSV -> Upstart -> systemd lost that functionality in systemd.

When I re-introduced SYSV-init support, I accidentally brought it back.
It was never supported in the first place.

Official has always been to set TMPDIR, or any of the four honored by mkstemp() prior to PMS launch .

What will happen now is I’m going to clean up this perpetuation of an error because there is no way for us to selectively pick variable names in service definitions.

The solution I’m going to implement is:

  1. I’ll set TMPDIR to the Plex default (which is per each platform’s default) /tmp
  2. If this isn’t desired, all that’s needed is to declare a new value in override.conf or /etc/default/plexmediaserver (platform dependent)

I will also be adding some support info in the service file and default file to clarify this.

Thanks for your work @ChuckPa

Not sure f i understand correctly: Right now /etc/default/plexmediaserver is ignored?
or just the

# where the mediaserver should store the transcodes
export PLEX_MEDIA_SERVER_TMPDIR=/tmp

directive?

Environment=PLEX_MEDIA_SERVER_TMPDIR=/tmp is in the .service file
Would that be honoured?

So there is no misunderstanding.

  1. I am removing all references to PLEX_MEDIA_SERVER_TMPDIR. It was a variable which never should have existed.

  2. The proper variables (per ISO/IEC) already exist: TMPDIR see also mkstemp() C++ std for temp files.

If you do this, you’ll be able to operate as you should and continue without interruption after I make the correction.

# where the mediaserver should store the transcodes
export TMPDIR=/tmp

Thanks for clearing that up.

One more thing:

TranscoderTempDirectory which is setable via gui, has nothing to do with the TMPDIR we are talking about? And why have 2 separate directories for basically the same thing?

You’re correct. The two are distinct.

  1. TMPDIR is for all the other things PMS does.
  2. The transcoder defaults to TMPDIR unless you expressly set it.

Here’s how I’m writing the new /etc/default/plexmediaserver
plexmediaserver.service will be similarly writtten.

Look ok?

# default Environment for Plex Media Server
# Uncomment and edit variables below as desired

# Where Plex keeps its metadata
#export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver/Library/Application Support"

# The number of plugins that can run at the same time
#export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6

# Limit the stack size
#export PLEX_MEDIA_SERVER_MAX_STACK_SIZE=3000

# Where Plex should perform temporary file work.
# The TranscoderTempDir can be set in either the Plex/Web GUI or in Preferences.xml
#export TMPDIR=/tmp

# the user that PMS should run as, defaults to 'plex'
# note that if you change this you might need to move
# the Application Support directory to not lose your
# media library (match what is in /etc/passwd)
# (plex_media_server_user has been retired in favor of plex_user on Debian)
#export PLEX_MEDIA_SERVER_USER=plex

# Uncomment this to use syslog for logging instead of
# sending logs to Plex Media Server.log
#export PLEX_MEDIA_SERVER_USE_SYSLOG=true

I think you meant the Scanner, since the Transcoder defaults to /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode and not TMPDIR?

I don’t see a reason to have the Scanner write its tmp files to another tmp dir than the Transcoder, unless there is a technical reason I am unaware of.
/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Scanner for example would be a more consistent default value and more inline with Plex’s insistence on having its own dir structure.

Also having those variables defined in a .service file makes it harder for users to edit since we need to make a copy to /etc/systemd/system/plexmediaserver.service which will not inherit subsequent changes provided by you in the package’s /lib/systemd/system/plexmediaserver.service file.

Edit:
It seems I am mistaken, it’s the Transcoder writing into /tmp while generating the Intro thingie which is even more puzzling to have 2 separate tmp dirs for the same thing. It should not use TMPDIR then but TranscoderTempDirectory which defaults to: /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode
Or have TranscoderTempDirectory default to TMPDIR and not /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode

This is incorrect use of a Linux service / override. Copying the entire service file isolates the installation because a fully overridden unit file will have been created when only a few variables were desired.

Please see man systemctl, specifically systemctl edit <servicename> to effect change to specific variables.

Also, please see specific examples I have provided in

Learned something new today, thank you!

My point of not having 2 tmp dirs for the Transcoder should still stand though?

  1. Defaults to one TMPDIR , which may be relocated . Usage suitable for most users
  2. Use of TranscoderTempDir is optional for those wishing finer control.

It won’t be split any more than that.

I don’t think I am understanding you correctly.
Are you saying that in future releases, when I watch a Show the temporary transcode files will go in /tmp by default and not into /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode anymore?

  1. The default Temporary directory (normal PMS operations) – NON transcoding, Non-scanning) is /tmp

  2. The default transcoder directory is indeed
    /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode

You can move both of those independently;

TMPDIR - Environment variable
TranscoderTempDir - GUI setting or Preferences.xml value

Ok then I think you misunderstood me, or I am explaining poorly.

This is not happening currently.

/usr/lib/plexmediaserver/Plex Transcode is writing some operations into /tmp.

plex     ... /usr/lib/plexmediaserver/Plex Transcoder -codec:1 ac3 -analyzeduration 20000000 -probesize 20000000 -i /srv/media/series/someshow/Season.02/someshow.mkv -filter_complex [0:1] aresample=async=1:ocl='5.1':osr=48000[0] -map [0] -metadata:s:0 language=eng -codec:0 pcm_s16le -b:0 768k -f wav -map_metadata -1 -map_chapters -1 -t 648.68949999999995 /tmp/dfcc847b-ce49-4d9d-8edb-598a7e3c306a -y -nostats -loglevel quiet -loglevel_plex error -progressurl http://127.0.0.1:32400/video/:/transcode/session/id/id/progress

Thats a transcode operation writing into /tmp/dfcc847b-ce49-4d9d-8edb-598a7e3c306a
This is the part I am talking about.

The Transcoder is sometimes not using TranscoderTempDir but TMPDIR.

He’s already said that it will be fixed.

this is simply a playlist of files for the transcoder to scan. it’s not a ‘transcode’ per se

Pretty big for a playlist:
930M 2ca9dcf7-c66a-4606-9c73-11e62ac0838c

This is another issue.