Please refer to recent Plex Media Server feature announcement as a direct replacement for Shaperr. This is a feature that has been requested for years and it may appear Plex has finally delivered.
https://www.plex.tv/blog/mcstreamy-brain-take-world-two-easy-steps/
https://support.plex.tv/hc/en-us/articles/227715247
( 2/26/2016: testable. please report issues. )
Supported platforms: Ubuntu Linux 12.04+
No server-side control over quality settings chosen by Plex client apps.
Plex client applications determine what video quality will be streamed from your Plex Media Server. The subsequent impact on PMS's upstream bandwidth usage can be substantial depending on where the server is homed.
Chunked buffering of Plex clients.
Transcoded videos aren't exactly "streamed" to the client with a smooth, consistent transport such as RTMP. Video is transcoded in chunks then pushed to the client at full wire speed. Like quality settings, this impacts bandwidth usage on the Plex server...
"So, for a 1Mbps video, it will max out my 4Mbps pipe 25% of the time and spend the other 75% idling. I use the same connection for gaming so lag spikes = death!"
RATE
and CEIL
ing limits. Each connection gets an isolated pipe.RATE
and CEIL
ing limits.SHAPERR is a collection of Linux shell scripts that, when properly configured and run, will tail
the active Plex Media Server log file looking for specific information. When SHAPERR sees a new "play" event logged by PMS, it captures the client IP address and the action ("start", "stop") then runs standard /sbin/tc
commands that establish outbound bandwidth throttling rules in the kernel and iptables firewall for that specific IP.
Clients that attempt to play at higher quality / bandwidth settings than those defined in the shaperr.conf
will see stuttering video and dropped frames. Lowering quality settings on the client app will allow them to stream smoothly (all things being equal). When the Plex client stops a video explicitly or plays it through the last second, Plex logs a "stop" event that we use to remove the bandwidth throttling rules and for that IP address.
NOTE: This method of implementing server side configuration changes is, at best, "mostly reliable" under ideal conditions. Using shell scripts to tail
a log file, searching for specific conditions (exactly what shaperr does), is the option of least preference over a professionally coded solution using a standard programming language of just about any flavor.
Most commands below will need to be executed as the root user or using sudo
.
Steps below assume git is already installed
git clone https://github.com/briankelley/shaperr
cp ./shaperr.conf.orig ./shaperr.conf
sh shaperr_start
Re-running the script at any time (step 6), so long as you do it as the root user, removes throttling for all currently connected streams and reinitializes the Plex logfile tail.
New "start" actions will be throttled.
There's probably better ways to do this, but this works for me. I run each of these commands inside independent putty SSH sessions then tile the windows to suit on a second monitor. You don't need to monitor all of these, but if you're a freak about understanding what's going on, this should help you scratch that itch. For more information about the info presented by these commands, see the man pages for each utility.
sudo watch -n 1 tc class show dev eth0
sudo watch -n 1 tc qdisc show dev eth0
sudo watch -n 1 tc -d filter show dev eth0
sudo watch -n 1 iptables -t mangle -L OUTPUT -v
sudo tail -Fq -n 0 /opt/shaperr/shaperr.log
sudo htop
Transcoder
, then Enter
sudo iftop
t
, t
, t
, T
, S
, >
, l
, 32400
(that's an "L")sudo iotop -P -o -d 2
SET_IPTABLES_2_DEFAULTS
.
2/26/2016
2/9/2016
tc
class handle. Randomization of the class handle to avoid duplication collision won't work since there's no IP <-> random number saving ability. The commands that implement traffic shaping are initiated based on data from tailing an active Plex log. Revisit if nosql db implemented at a later date.RATE
, MAXRATE
, and SERVERMAX
may turn out to be as much "black art" as SEO. YMMV.tc
class id namingtc
commands