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] Implement HTB QoS for PMS on CentOS 6.4

plexcloud.tvplexcloud.tv Members, Plex Pass Posts: 79 Plex Pass
edited May 2013 in Linux

For those in the dark about how to limit/prioritize streaming bandwidth for servers running PMS; here is a guide dictating my personal method.

An alternate method is described in this thread and only requires /sbin/tc.


**If you are streaming from a server w/o the necessary kernel modules for traffic control (usually a dedicated server), follow my thread at torrent-invites to re-compile your linux kernel and include the appropriate modules for linux QoS**



HTB.init is a shell script derived from CBQ.init that allows for easy setup of HTB-based traffic control on Linux. HTB (Hierachical Token Bucket) is a new queueing discipline which attempts to address the weaknesses of current CBQ implementation.


1) Dependencies

First, ensure that you have the iproute package installed & module-loading kernel support**

# yum install iproute


2) Setup

Download the 'htb.init' from sourceforge and stick this file into /etc/init.d/ . Next, create the directory for storing our traffic classes: /etc/sysconfig/htb

# wget http://sourceforge.net/projects/htbinit/files/HTB.init/0.8.5/htb.init-v0.8.5/download
# mv htb.init-v0.8.5 /etc/init.d/htb.init
# chmod 755 /etc/init.d/htb.init
# mkdir /etc/sysconfig/htb && cd /etc/sysconfig/htb


3) Define our ethernet device

The first file we create, 'eth0', specifies which device we are to create traffic rules for

# vi eth0


The contents of this file are rather simple: The DEFAULT directive specifies which rule number (ie. 99) we'll default to when no other rules match and the bandwidth rate (set in next step(s) ) divided by R2Q gives us our quantum, which is the amount of bandwidth given to one class before servicing another class. The faster your available network connection, the larger your quantum can be. This is the configuration for my 100mbps link server.


4) Define our total bandwidth

# vi eth0-2.root


The default RATE is the minimum rate for the class (device eth0 in this case). The CEILing is the maximum rate for the class. Finally, the BURST rate is the maximum amount of bandwidth that can be sent through the hardware without moving on to service another class. It is recommended to set the RATE 'just below' your maximum bandwidth to prevent buffering performed by auxiliary network equipment, but here I have chosen the maximum throughput value of my box as I'm confident my datacenter has accounted for this already.


5) Creating our class rule(s)

# vi eth0-2:10.plex



The heart of this tutorial lies with the configuration of this particular rule file. I set my Plex (source port 32400) traffic to be given a minimum rate of 2Mbit, and a maximum of 3Mbit. This traffic also has the highest priority (1). WIth this configuration, each client can utilize 'Direct Play' and theoretically I can serve 30 clients at any given time. 

*future amendments to this rule would be to explicitly exclude neutral outgoing traffic from PMS meta-agent queries

**Rules are specified with the pattern RULE=saddr[/prefix[:port[/mask]],][daddr[/prefix]][:port[/mask]]


6) Creating our default rule

# vi eth0-2:99.dfl



7) Final configurations

To start using the rules and make them persistent on every reboot, we need to add the htb.init service to the system, set it to start on boot, and turn it on:


# chkconfig --add htb.init
# chkconfig htb.init on
# service htb.init start


8) Post-Installation

One quick way to check that QoS is working is to download a video from your PMS server via Plex/Web and if the download speed is within the threshold, then you've succeeded.

Sign In or Register to comment.