briankelley / shaperr

Traffic shaping for Plex Media Server
MIT License
13 stars 1 forks source link

SHAPERR

10/3/2016 Plex releases server-side bandwidth management feature.

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

Traffic shaping for Plex Media Server

( 2/26/2016: testable. please report issues. )

Supported platforms: Ubuntu Linux 12.04+

What's the matter with Plex?

What does SHAPERR do?

How does it work?

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.

How do I install it and configure it?

Most commands below will need to be executed as the root user or using sudo.

Steps below assume git is already installed

  1. optional: start your monitoring windows (below) if you haven't already.
  2. change directories to /opt
  3. git clone https://github.com/briankelley/shaperr
  4. cp ./shaperr.conf.orig ./shaperr.conf
  5. edit settings in shaperr.conf
  6. as the root user (not sudo) sh shaperr_start
  7. you can exit root when the prompt returns

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.

Monitoring

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.

Troubleshooting


Known issues

Changes / Activity

2/26/2016

2/9/2016

To-do

Wishlist