RTMP Scaling
Study
* It was found that RTMP Origin servers can only relay to multiple edges. These edges can be useful for
Geographically distributing the content.
* There is no internal intelligent and dynamic loadbalancing in any available solutions, except commercial solutions like
Wozwa or Red5Pro again these are custom plug-ins or code.
* This area still requires more research and we are progressing.
| #######################
|~~~~~~~~~~~~~~~| |<------------------># RTMP Server 1 #
| | ################# | #######################
| Clients |<--------------># Load Balancer # <--------------->|
| | ################# | #######################
|_______________| |<------------------># RTMP Server 2 #
| #######################
Specification of Test environment
Platform - CentOS 6.x/Debian/Ubuntu
Load Balancer - Haproxy - Version - v1.6.x (generic configuration will do)
RTMP Streamer - Nginx-RTMP-Module compiled with Nginx (any version) (https://github.com/arut/nginx-rtmp-module)
RTMP Stress test - flazr (java client) (http://flazr.com)
Note : There is no need to modify code unless we need dynamic load balancing,
as nginx-rtmp-module can publish statistics about connections and uptime.
Installing Nginx with RTMP-Module
yum install gcc g++ automake wget epel-release pcre-devel pcre openssl-devel git
cd /opt
git clone https://github.com/arut/nginx-rtmp-module
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar xvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --add-module=/opt/nginx-rtmp-module/ --with-http_ssl_module --prefix=/usr/local/nginx-streaming/
make
make install
Installing Haproxy
Please refer : https://wiki.exphosted.com/doku.php/haproxy_changes - Roll-back scenario - script section (we can use any version of haproxy)
Haproxy Configuration
global
user root
group root
spread-checks 1
defaults
timeout client 30s
timeout server 30s
timeout connect 1s
timeout queue 2s
max-keep-alive-queue 1900
option tcp-smart-accept
option tcp-smart-connect
option tcpka
option srvtcpka
option clitcpka
option redispatch
retries 3
maxconn 2000
no option log-health-checks
log 127.0.0.1 local1
frontend rtmp
bind 192.168.56.12:1935 transparent
maxconn 1900
tcp-request inspect-delay 2s
default_backend rtmp_end
backend rtmp_end
mode tcp
option tcplog
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 20m
stick on src
server edge1 192.168.56.10:1935 check port 1935 weight 10 minconn 10 check maxconn 1000
server edge2 192.168.56.11:1935 check port 1935 weight 10 minconn 10 check maxconn 1000
Nginx Configuration
worker_processes 1;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935;
chunk_size 2000;
# RTMP URL : rtmp://<IPADDR>/<application Name>/<media_file>.mp4|flv
application learnexa {
live on;
# Path where the MP4 or FLV's are kept
play /usr/local/nginx-streaming/streams;
}
}
}
http{
server {
listen 80;
location / {
root /usr/local/nginx-streaming/html;
}
location /control {
rtmp_control all;
}
location /stat {
rtmp_stat live;
}
}
}