Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

HOWTO limit plex media server bandwidth on linux

rodalphoidrodalphoid Members Posts: 24 ✭✭
edited April 2012 in Linux
PMS traffic shaping on linux
I just started using Plex recently. My home router (an Asus RTN-56u, so please don't tell me to get a WRT54GL with DDWRT) doesn't handle QoS properly, and I'm allowing people access to my PMS that may not comply with my request to limit streaming speeds, so I wanted to limit PMS's outgoing speed at the linux level. There are several ways to do this; the easiest is to start PMS with a program called "trickle", but from what I could tell, trickle sounds awesome but simply does not work. My way is much more complicated, but with a cheatsheet here, it should be fairly easy to follow.

I hope this helps someone; traffic shaping on Linux is surprisingly badly documented. I had to go back to manpages and one guy's FAQ on a blog dated 2010 to get this working.

Drop this in /etc/rc.local. It will limit the server to a maximum of 2500 kilobits outgoing on port 32400.

#######
### Setup Traffic Control to limit outgoing bandwidth
### Sourced from
### http://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic/
#######

### Sleep for a second
sleep 1

### Delete all TC rules for eth0 
/sbin/tc qdisc del dev eth0 root

### Activate queueing discipline
/sbin/tc qdisc add dev eth0 root handle 1:0 htb

### Define class allowed 2500kbit burst to 2500kbit (kbps=kiloBYTES)
/sbin/tc class add dev eth0 parent 1:0 classid 1:10 htb rate 2500kbit ceil 2500kbit prio 0

### Create iptables mangle rule for outgoing port 32400 (Plex Media Server)
/sbin/iptables -A OUTPUT -t mangle -p tcp --sport 32400 ! --dst 192.168.5.0/24 -j MARK --set-mark 10

### Assign the rule to the proper qdisc
/sbin/tc filter add dev eth0 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10

### Notes
## show TC rules
# /sbin/tc -s -d class show dev eth0
## Show iptables mangle rules
# /sbin/iptables -t mangle -n -v -L
## Show actual bandwidth being used on 32400
# watch -n 1 /sbin/tc -s -d class show dev eth0
«1

Comments

  • elanelan CTO and Co-founder MauiMembers, Plex Employee, Plex Pass, Plex Ninja Posts: 9,317 Plex Employee
    Thanks for posting this, and welcome to the Plex forums!
  • rodalphoidrodalphoid Members Posts: 24 ✭✭
    edited April 2012
    Happy to be here, and please don't let this post dissuade you guys from adding bandwidth limiting to upcoming releases of PMS, hint hint!

    Edit: I changed one line, the iptables mark. It was restricting bandwidth to my home network, which I didn't want. This line now restricts bandwidth to everything BUT my home network. If your network isn't on 192.168.5.*, change it accordingly.

    And yes the ! is in the right spot. It looks wrong to me too.
  • Darknight670Darknight670 Members Posts: 27 ✭✭
    Is it possible to shape traffic per user ( i.e. per IP ) ??
  • rodalphoidrodalphoid Members Posts: 24 ✭✭
    Sure. The iptables line "marks" packets that match certain descriptions. The description I wrote in my post matches all packets that:

    1) aren't going to destination address 192.168.5.* (my home network)
    2) come from source port 32400 (the PMS port)

    If you wanted to shape all traffic going to 10.147.34.7 and 10.147.34.8, for example, you could use two iptables lines

    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 32400 --dst 10.147.34.7 -j MARK --set-mark 10
    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 32400 --dst 10.147.34.8 -j MARK --set-mark 10
    


    You can also use a match iprange flag and dst-range 10.147.34.7-10.147.34.8, if you want to get fancy-- read the iptables manpage for more info. It's not exactly trivial to wrap your brain around; lots of linux distros include tools that manage iptables for you like ufw on Ubuntu, and even gufw to provide a GUI around the wrapper. But it's not crazy tough either.

    Additionally, if you want to provide different amounts of bandwidth to different destination IPs, you can do that too. The secret is the classid. In my example, the classid is 10. So every spot where you see 10, you could substitute it with 7, for example, and create multiple classes. You can also setup real QoS (as opposed to just restricting bandwidth) by prioritizing connections using the "prio" flag, so both Bob and Jane can stream 1500kbit, but if both connect Bob gets all his bandwidth before Jane gets any.
  • Reale_ESReale_ES Members Posts: 13 ✭✭

    Wery Nice Scritp... Same use for me... Sharing Medias with Frends!!

    Nice Work...

  • Reale_ESReale_ES Members Posts: 13 ✭✭

    I have a Problem with this part of de Script

    /sbin/tc qdisc del dev eth0 root
    

    I Cannot run it...

    The resutl of the command is:

    RTNEETLINK answers: no such file or directory
    

    Can you help me resolv that problem?

    Regard Reale

  • adamrathsackadamrathsack Members, Plex Pass Posts: 5 Plex Pass

    Thank you so much for this!

  • realpariahrealpariah Members, Plex Pass Posts: 324 Plex Pass
    edited September 2013
    rodalphoid wrote on April 5 2012, 11:05 PM: »

    I just started using Plex recently. My home router (an Asus RTN-56u, so please don't tell me to get a WRT54GL with DDWRT) doesn't handle QoS properly, and I'm allowing people access to my PMS that may not comply with my request to limit streaming speeds, so I wanted to limit PMS's outgoing speed at the linux level. There are several ways to do this; the easiest is to start PMS with a program called "trickle", but from what I could tell, trickle sounds awesome but simply does not work. My way is much more complicated, but with a cheatsheet here, it should be fairly easy to follow.

    I hope this helps someone; traffic shaping on Linux is surprisingly badly documented. I had to go back to manpages and one guy's FAQ on a blog dated 2010 to get this working.

    Drop this in /etc/rc.local. It will limit the server to a maximum of 2500 kilobits outgoing on port 32400.
     

    #######
    ### Setup Traffic Control to limit outgoing bandwidth
    ### Sourced from
    ### http://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic/
    #######
    
    ### Sleep for a second
    sleep 1
    
    ### Delete all TC rules for eth0 
    /sbin/tc qdisc del dev eth0 root
    
    ### Activate queueing discipline
    /sbin/tc qdisc add dev eth0 root handle 1:0 htb
    
    ### Define class allowed 2500kbit burst to 2500kbit (kbps=kiloBYTES)
    /sbin/tc class add dev eth0 parent 1:0 classid 1:10 htb rate 2500kbit ceil 2500kbit prio 0
    
    ### Create iptables mangle rule for outgoing port 32400 (Plex Media Server)
    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 32400 ! --dst 192.168.5.0/24 -j MARK --set-mark 10
    
    ### Assign the rule to the proper qdisc
    /sbin/tc filter add dev eth0 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
    
    ### Notes
    ## show TC rules
    # /sbin/tc -s -d class show dev eth0
    ## Show iptables mangle rules
    # /sbin/iptables -t mangle -n -v -L
    ## Show actual bandwidth being used on 32400
    # watch -n 1 /sbin/tc -s -d class show dev eth0
    

    LoL, I can report I use DD-WRT on a 54G [could be any number of routers DD-WRT is not limited to Only WRTs just got its start with them], and QOS works great using HTB [as specified in the documentation the HFSC is still known to have certain issues in older versions of DD-WRT [well at least online documentation I read and not sure what versions and don't want to go testing my router runs for several years without intervention as a client bridge and the performance is stellar so no need].

    The hardest part with any QOS is actually finding the correct speed settings they need to be lower than your actual speed because what QOS is for is to essentially create a bottleneck at your router your QOS has control over rather than run in to random bottlenecks which is does not [some ISPs even do that speed boost deal and if you do a quick speed test and set your limits based on these values rather than what really should be used [the value RIGHT under which your can run constant consistent connections].  As I said this is the HARDEST part of QOS and requires a ton of testing multiple times to multiple clients in multiple scenarios and all to get correct.

    If you set your values to high for your own connection this breaks QOS and can stop almost all traffic period resulting in what APPEARS to be a broken QOS setup that is actually just misconfigured.

    From DD-WRT QOS wiki

    "It probably bugs you to set less than 100% of your available bandwidth in these fields but this is required. There will be a bottleneck somewhere in the system and QoS can only work if the bottleneck is in your router where it has control. The goal is to force the bottleneck to be in your router as opposed to some random location out on the wire over which you have no control. Some ISP's even have bursting ("powerboost") which will temporarily give you extra bandwidth when you first start using your connection but will later throttle down to a sustained rate. Fortunately there is usually a minimum level that you receive on a consistent basis and you must set your QoS limits below this minimum. The problem is finding this minimum and you may have to repeat speed tests many times before determining it. For this reason start with 80% of your measured speed and try things for a couple of days. If the performance is acceptable you can start to inch your levels up. If you go even 3% higher than you should be, your QoS will totally stop working (just too high) or randomly stop working (high when your ISP is slow). This can lead to a lot of confusion on your part so get it working first by conservatively setting these speeds and then optimize later."

    http://www.dd-wrt.com/wiki/index.php/Quality_of_Service#Initial_Setup

  • MaxMaximeMaxMaxime Members, Plex Pass Posts: 41 Plex Pass
    edited September 2013

    I don't see how IP filtering could provide per user limitations. Say I shared my media with a friend. He will access the server via it's url from multiple different locations, and so will I. 

    Does anyone know how we could do this ? I guess there has to be some sort of mention, at some time, of the user name in the transfer. 


    EDIT: Or we could create a database with username and originating ip, and have iptables use those. 

  • wickning1wickning1 Members, Plex Pass Posts: 119 Plex Pass

    Thank you for this script, I've been searching all night for something to accomplish this seemingly simple task.  I haven't tested it yet, but I will tomorrow.

    I did need to change something:

    /sbin/tc qdisc del dev eth0 root

    to

    /sbin/tc qdisc del dev eth0 root 2> /dev/null || /bin/true

    because this line was producing a bad exit code (and the error Reale mentioned) when no rules existed to be deleted.  This caused rc.local to halt execution entirely since rc.local doesn't tolerate failure.

  • danopiadanopia Members, Plex Pass Posts: 3 Plex Pass

    Why isn't this option settable from the PMS side? :<

    I'm wondering how external caps (self-imposed, or isp-set) affects existing direct-stream plays when bandwidth runs out. Do those streams switch to PMS-side transcodings automatically? Is quality automaticly set?

    My PMS runs on a linux box which is also the network router so I have eth0 for upstream and eth1 for local. Basically that means I don't have dd-wrt in the way to provide QoS. If I want QoS I need to apply it in linux myself, which is why this method would be useful.

  • wickning1wickning1 Members, Plex Pass Posts: 119 Plex Pass
    edited December 2013

    I second the idea that this would be really useful on the PMS side.  I don't really need a hard limit per client though, what I need is smoother buffering.

    The whole reason I do this is because some clients have a tendency to buffer in insane bursts that bring my internet to its knees.  So on a 1Mbps video, it will max out my 4Mbps pipe 25% of the time, and spend the other 75% idling, leaving me with big lag spikes in my game at regular intervals.  If it would just use half of my capacity for 50% of the time, I'd have no problem whatsoever.  That is basically what this accomplishes.

    I can't answer how it behaves when it runs out, my videos are generally all low enough bitrate to fit inside this cap.

  • PinkyThePiggyPinkyThePiggy Members, Plex Pass Posts: 235 Plex Pass
    danopia wrote on December 17 2013, 9:20 PM: »

    Why isn't this option settable from the PMS side? :<

    I'm wondering how external caps (self-imposed, or isp-set) affects existing direct-stream plays when bandwidth runs out. Do those streams switch to PMS-side transcodings automatically? Is quality automaticly set?

    My PMS runs on a linux box which is also the network router so I have eth0 for upstream and eth1 for local. Basically that means I don't have dd-wrt in the way to provide QoS. If I want QoS I need to apply it in linux myself, which is why this method would be useful.

    Most (all?) home connections don't throttle when over a cap. They instead get charged more, get shut off entirely or get a nastygram from their ISP.

    But... Plex would just sit there trying to buffer. The client/server doesnt choose bandwidth usage. The user does. So it would try and buffer until the user changed their settings.

    As to how this could be implemented... I suggest skipping a technically viewable/settable bandwidth cap inside plex and instead go the route of allowing certain streaming options per user. e.g. User A is not allowed to choose a streaming option that uses over 10mbps. or not allowed to choose over 5mbps etc. Then also have a setting on the server itself that caps the number of streaming connections that can be open to the server at any given time. So you limit all users to 4mbps streams and set your server to have a max number of streams at 5 for a server owner who has a cap of 20mbps upload. Also have an option on server to exclude these options while on local network.

    This would be vastly more user friendly and provides at least basic QoS on a per user basis.

  • mrbubbles02mrbubbles02 Members, Plex Pass Posts: 37 Plex Pass
    edited January 2014

    Running Fedora 20, I had to run

    modprobe sch_htb

    as well as add 'default 0' to the following line:

    /sbin/tc qdisc add dev eth0 root handle 1:0 htb

    Without 'default 0', I got

    RTNETLINK answers: Invalid argument

    I have made a few modifications to the script posted earlier by realpariah, including a small systemd service that runs automatically on boot to re-configure the traffic shaping rules and the addition of a round-robin SFQ (Stochastic Fair Queuing) scheduler for the clients, which ensures that bandwidth is distributed equally if there is not enough bandwidth to go around. From my small tests so far, it seems to work well enough.

    It doesn't support per-user limits, but does enable you to specify an absolute limit for Plex's bandwidth and then a target limit.

    • Under high traffic demands, it will attempt to use no more than the target rate (as of yet untested; I have a hunch it may always use the absolute limit. May require an additional traffic shaping class definitions matching all non-plex ports to get this part working)
    • If too many users are connected and there isn't enough bandwidth to share, the system allocates bandwidth in a round-robin fashion ensuring that users who have specified a smaller bitrate in their Plex preferences will buffer more quickly than those hogging the bandwidth by using direct play or whatever.
    • If too few users are connected, then that user is allowed to use up to the maximum limit (even if this is above the target limit).

    Run the following to set it up:

    cat << EOF > /usr/local/bin/plex-traffic-shape
    #!/bin/sh
    # Setup Traffic Control to limit outgoing bandwidth
    # Sourced from:
    #   * http://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic
    #   * https://forums.plex.tv/index.php/topic/39823-howto-limit-plex-media-server-bandwidth-on-linux/?p=466013
    #   * http://serverfault.com/questions/174010/limit-network-bandwith-for-an-ip
    #   * http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm
    #
    # Ensure that the sch_htb module is available.
    # For very high rates, you may need to adjust the quantum values. See: http://mailman.ds9a.nl/pipermail/lartc/2003q1/007508.html
    
    usage() {
      echo "\$0 ifdev rate maxrate ipblock"
      echo -e "\tifdev is usually eth0"
      echo -e "\trate and maxrate are a rate accepted by tc (e.g. 500kbit, 1mbit)"
      echo -e "\tipblock is a IP block per iptables syntax (e.g. 192.168.1.0/24"
      exit 1
    }
    
    IFDEV=\$1
    RATE=\$2
    MAXRATE=\$3
    R2Q=\$4
    IPBLOCK=\$5
    
    if [ -z \$IFDEV ] || [ -z \$RATE ] || [ -z \$MAXRATE ] || [ -z \$R2Q ] || [ -z \$IPBLOCK ];then
      usage;
    fi
    
    ### Modules
    modprobe sch_htb
    
    ### Sleep for a second
    sleep 1
    
    ### Delete all TC rules for \$IFDEV
    /sbin/tc qdisc del dev \$IFDEV root 2> /dev/null || /bin/true
    
    ### Delete the iptables mangle rule if it exists
    /sbin/iptables -D OUTPUT -t mangle -p tcp --sport 32400 ! --dst "\$IPBLOCK" -j MARK --set-mark 10  2> /dev/null || /bin/true
    
    ### Activate queueing discipline
    /sbin/tc qdisc add dev \$IFDEV root handle 1: htb default 20 r2q "\$R2Q"
    
    ### Define class with limited allowed bandwidth
    
    /sbin/tc class add dev \$IFDEV parent 1: classid 1:1 htb rate "\$MAXRATE" ceil "\$MAXRATE"
    /sbin/tc class add dev \$IFDEV parent 1:1 classid 1:10 htb rate "\$RATE" ceil "\$MAXRATE"
     
    ### Send packets in round-robin if we have too many clients and too little BW
    /sbin/tc qdisc add dev \$IFDEV parent 1:10 handle 100: sfq perturb 10
     
    ### Create iptables mangle rule for outgoing port 32400 (Plex Media Server)
    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 32400 ! --dst "\$IPBLOCK" -j MARK --set-mark 10
     
    ### Assign the rule to the proper qdisc
    /sbin/tc filter add dev \$IFDEV parent 1: prio 3 protocol all handle 10 fw flowid 1:10
     
    ### Notes
    ## Source variables
    # . /etc/sysconfig/plex-traffic-shape
    ## show TC rules
    # /sbin/tc -s -d class show dev \$IFDEV
    ## Show iptables mangle rules
    # /sbin/iptables -t mangle -n -v -L
    ## Show actual bandwidth being used on 32400
    # watch -n 1 /sbin/tc -s -d class show dev \$IFDEV
    EOF
    
    chmod +x /usr/local/bin/plex-traffic-shape
    
    cat << EOF > /etc/sysconfig/plex-traffic-shape
    # Interface to enable traffic shaping on.
    IFDEV="p3p1"
    
    # Define your "fair-share" rate and maximum uplink for Plex.
    # Valid suffixes:
    # kbit - kilobits/s;
    # mbit - megabits/s;
    # kbps - kilobytes/s;
    # mbps - megabytes/s;
    RATE="3mbit"
    MAXRATE="8mbit"
    
    # The rates above converted to bytes/s divided by this number should fall
    # anywhere between 1500 and 60,000. It's used to evenly distribute surplus
    # bandwith: http://www.docum.org/faq/cache/31.html
    R2Q=50
    
    # Your local IP block to exclude from traffic shaping. To disable traffic
    # shaping exclusion (i.e., to enable it on your LAN as well) enter '127.0.0.1'
    # as-is with no subnet modifier.
    IPBLOCK="10.0.1.0/24"
    EOF
    
    cat << EOF > /etc/systemd/system/plex-traffic-shape.service
    [Unit]
    Description=Starts traffic shaping for Plex Media Server
    After=plexmediaserver.target
     
    [Service]
    EnvironmentFile=-/etc/sysconfig/plex-traffic-shape
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=-/usr/local/bin/plex-traffic-shape $IFDEV $RATE $MAXRATE $R2Q $IPBLOCK
     
    [Install]
    WantedBy=multi-user.target
    EOF
     
    systemctl daemon-reload
    systemctl enable plex-traffic-shape
    

    Now edit /etc/sysconfig/plex-traffic-shape according to your needs When you're all set:

    systemctl start plex-traffic-shape
  • Rick P.Rick P. Members, Plex Pass Posts: 58 Plex Pass
    edited January 2014
    PinkyThePiggy wrote on December 17 2013, 10:03 PM: »

    Most (all?) home connections don't throttle when over a cap. They instead get charged more, get shut off entirely or get a nastygram from their ISP.

    This generalized statement may be true in parts of the US but remember that users of this board could be from anywhere. North of the 49th this isn't an uncommon practice from the smaller ISPs - the big ones are generally happy to let you do what you want and charge dearly for the priviledge. On certain plans my ISP throttles during peak times when their internet bandwidth nears their contracted maximum, without charging more. Since they manage their network to avoid overage fees to the telco or cable suppliers they don't have to track usage or bill their customers for it. Other providers throttle when you hit a cap but ensure you've got enough bandwidth for basic web browsing, email and VOIP. I don't have a cap to worry about and my service is not affected by throttling.

    Re user-based settings I kind of like this idea. My kids and wife are much less particular than I am and are more than happy watching low bandwidth streams. However, none of them would think to change settings on a client which I may have set to use a 10 mbps stream.

  • rodalphoidrodalphoid Members Posts: 24 ✭✭

    Happy to see people still find this useful.

    I still think rate throttling really should be in the plex media server itself. But hey, it's free, so I can't make a huge fuss.

  • zstar69zstar69 Members Posts: 42 ✭✭

    Very slick. Works like I wanted it to. Thanks man.

  • kopfpilotkopfpilot Members, Plex Pass Posts: 281 Plex Pass
    edited January 2016

    And this is the upstart version, tested on ubuntu 14.04.

    It is basicly what mrbubble02 posted, with following differences;

    • folder and name of init script changed
    • init script converted into upstart schema
    • folder for the config script changed
    • systemctl calls have been replaced by initctl calls

    Open a root shell and paste the code block into it.
    All files will be created with proper permissions.

    cat &lt;&lt; EOF &gt; /usr/local/bin/plex-traffic-shape
    #!/bin/sh
    # Setup Traffic Control to limit outgoing bandwidth
    # Sourced from:
    #   * http://www.cyberciti.biz/faq/linux-traffic-shaping-using-tc-to-control-http-traffic
    #   * https://forums.plex.tv/topic/39823-howto-limit-plex-media-server-bandwidth-on-linux/?p=466013
    #   * http://serverfault.com/questions/174010/limit-network-bandwith-for-an-ip
    #   * http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm
    #
    # Ensure that the sch_htb module is available.
    # For very high rates, you may need to adjust the quantum values. See: http://mailman.ds9a.nl/pipermail/lartc/2003q1/007508.html
    
    usage() {
      echo "\$0 ifdev rate maxrate ipblock"
      echo -e "\tifdev is usually eth0"
      echo -e "\trate and maxrate are a rate accepted by tc (e.g. 500kbit, 1mbit)"
      echo -e "\tipblock is a IP block per iptables syntax (e.g. 192.168.1.0/24"
      exit 1
    }
    
    IFDEV=\$1
    RATE=\$2
    MAXRATE=\$3
    R2Q=\$4
    IPBLOCK=\$5
    
    if [ -z \$IFDEV ] || [ -z \$RATE ] || [ -z \$MAXRATE ] || [ -z \$R2Q ] || [ -z \$IPBLOCK ];then
      usage;
    fi
    
    ### Modules
    modprobe sch_htb
    
    ### Sleep for a second
    sleep 1
    
    ### Delete all TC rules for \$IFDEV
    /sbin/tc qdisc del dev \$IFDEV root 2&gt; /dev/null || /bin/true
    
    ### Delete the iptables mangle rule if it exists
    /sbin/iptables -D OUTPUT -t mangle -p tcp --sport 32400 ! --dst "\$IPBLOCK" -j MARK --set-mark 10  2&gt; /dev/null || /bin/true
    
    ### Activate queueing discipline
    /sbin/tc qdisc add dev \$IFDEV root handle 1: htb default 20 r2q "\$R2Q"
    
    ### Define class with limited allowed bandwidth
    
    /sbin/tc class add dev \$IFDEV parent 1: classid 1:1 htb rate "\$MAXRATE" ceil "\$MAXRATE"
    /sbin/tc class add dev \$IFDEV parent 1:1 classid 1:10 htb rate "\$RATE" ceil "\$MAXRATE"
    
    ### Send packets in round-robin if we have too many clients and too little BW
    /sbin/tc qdisc add dev \$IFDEV parent 1:10 handle 100: sfq perturb 10
    
    ### Create iptables mangle rule for outgoing port 32400 (Plex Media Server)
    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 32400 ! --dst "\$IPBLOCK" -j MARK --set-mark 10
    
    ### Assign the rule to the proper qdisc
    /sbin/tc filter add dev \$IFDEV parent 1: prio 3 protocol all handle 10 fw flowid 1:10
    
    ### Notes
    ## Source variables
    # . /etc/default/plex-traffic-shape
    ## show TC rules
    # /sbin/tc -s -d class show dev \$IFDEV
    ## Show iptables mangle rules
    # /sbin/iptables -t mangle -n -v -L
    ## Show actual bandwidth being used on 32400
    # watch -n 1 /sbin/tc -s -d class show dev \$IFDEV
    EOF
    
    chmod +x /usr/local/bin/plex-traffic-shape
    
    cat &lt;&lt; EOF &gt; /etc/default/plex-traffic-shape
    # Interface to enable traffic shaping on.
    IFDEV="p3p1"
    
    # Define your "fair-share" rate and maximum uplink for Plex.
    # Valid suffixes:
    # kbit - kilobits/s;
    # mbit - megabits/s;
    # kbps - kilobytes/s;
    # mbps - megabytes/s;
    RATE="4mbit"
    MAXRATE="10mbit"
    
    # The rates above converted to bytes/s divided by this number should fall
    # anywhere between 1500 and 60,000. It's used to evenly distribute surplus
    # bandwith: http://www.docum.org/faq/cache/31.html
    R2Q=50
    
    # Your local IP block to exclude from traffic shaping. To disable traffic
    # shaping exclusion (i.e., to enable it on your LAN as well) enter '127.0.0.1'
    # as-is with no subnet modifier.
    IPBLOCK="192.168.0.0/24"
    EOF
    
    cat &lt;&lt; EOF &gt; /etc/init/plex-traffic-shape.conf
    description "Starts traffic shaping for Plex Media Server"
    
    # start in normal runlevels when disks are mounted and networking is available
    start on runlevel [2345]
    
    # stop on shutdown/halt, single-user mode and reboot
    stop on runlevel [016]
    
    env config=/etc/default/plex-traffic-shape
    script
        . config
        exec /usr/local/bin/plex-traffic-shape $IFDEV $RATE $MAXRATE $R2Q $IPBLOCK
    end script
    EOF
    

    Reload upstart configuration:
    initctl reload-configuration

    Start plex-traffic-shape:
    start plex-traffic-shape

  • MindsShadowMindsShadow Members, Plex Pass Posts: 8 Plex Pass

    Thanks guys, using this thread i got plex rate limiting working on my ubuntu plex server.

  • B0ZB0Z Members, Plex Pass Posts: 5 Plex Pass

    rodalphoid, kopfpilot, zstar69... I'm interested in knowing how the traffic shaping works in practice. Are there any complaints from your users?

«1
Sign In or Register to comment.