Advanced load balancing
Clustering events appear here
Server-side load balancing is usually done using a load balancer running in front of the RTMP or HTTP streaming servers. In this example the plugin first connects this server-side load balancer. If this connection fails the plugin switches to client side load balancing.
HTML
<!-- player container-->
<a href="Extremists.flv" class="player"
style="display:block;width:425px;height:300px;margin:10px auto"
id="hwBalancer">
<!-- splash image inside the container -->
<img src="/media/img/home/flow_eye.jpg"
alt="Search engine friendly content" /></a>
Configuration
We have three hosts on our cluster configured in our hosts property. The
first host is our server side load balancer. It's an imaginary host and will
never answer in reality. In normal situations it would serve video files when
it's up and running. When this host fails the onConnectFailed event is
called and we will dynamically switch to client side load balancing by using
setLoadBalancing(true) method. The plugin remembers the failing host and
will not use that after the first failed connection attempt.
// a global variable that references our info box
var info = document.getElementById("balanceInfo");
flowplayer("hwBalancer", "http://releases.flowplayer.org/swf/flowplayer-3.2.11.swf", {
clip: {
url: 'flowplayer.flv',
urlResolvers: 'cluster',
onStart: function(clip) {
info.innerHTML += "started clip: " + clip.url;
}
},
plugins: {
cluster: {
url: "http://releases.flowplayer.org/swf/flowplayer.cluster-3.2.8.swf",
hosts: [
// server side load balancer
'http://balance.flowplayer.org/video',
// direct URLs to the servers behind the balancer
'http://pseudo01.hddn.com/vod/demo.flowplayervod/Extremists.flv',
'http://stream.flowplayer.org/Extremists.flv'
],
onConnectFailed: function(host, index) {
// host at index 0 is the load balancer
if (index == 0) {
info.innerHTML += "server-side load balancer failed, " +
"enabling client-side load balancing<br/>"
;
this.setLoadBalancing(true);
}
},
onConnect: function(host, index) {
info.innerHTML += "attempting to connect to: " + host + "<br />";
}
}
}
});
