Load balancing servers with cluster plugin Streaming Extensions - Demo 7 / 13
Introduction
The cluster plugin can be set to randomly pick hosts from the cluster. This allows for simple load balancing completely controlled on the client side. This will improve performance. Click on the splash to see this in action.
HTML coding
Player container and the info box.
<!-- player container-->
<a
href="Extremists.flv"
style="display:block;width:425px;height:300px;"
id="balancer">
<!-- splash image inside the container -->
<img src="/img/home/flow_eye.jpg" alt="Search engine friendly content" />
</a>
<!-- info box -->
<div class="box" id="balanceInfo">
<h2>Clustering events appear here</h2>
</div>
Flowplayer configuration
We have two different video servers. static.flowplayer.org is hosted by Simple CDN and the other server is our own server. These two are accessed randomly so that at the end both servers will get loaded evenly. The load balancing is enabled with loadBalance property.
// a global variable that references our info box
var infoBox = document.getElementById("balanceInfo");
flowplayer("balancer", "http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf", {
// configuration for the clustering plugin
plugins: {
cluster: {
url: 'flowplayer.cluster-3.2.3.swf',
// two working hosts
hosts: [
'http://pseudo01.hddn.com/vod/demo.flowplayervod',
'http://pseudo01.hddn.com/vod/demo.flowplayervod'
],
// that are load balanced (accessed randomly)
loadBalance: true,
// callback method that updates our info box
onConnect: function(host, index) {
infoBox.innerHTML += "attempting to connect to: " + host + "<br />";
}
}
},
clip: {
// our clip uses clustering plugin
urlResolvers: 'cluster',
onStart: function(clip) {
infoBox.innerHTML += "started clip: " + clip.url;
}
}
});
Take a look at a standalone version of this demo. View its source code to get things going on your page.