You will recieve your password to this address. Address is not made public.

Your preferred username that is used when logging in.

Streaming plugin: cluster Gain performance and reliability by streaming from multiple servers

Introduction

The Cluster plugin is used to configure multiple streaming sources. By having multiple sources we gain reliability because the viewer is less likely to be affected if some of the sources are not available. We also gain performance because we can balance the load by distributing the viewers between several servers.

(Version 3.2.2)

Features

Example

Here we have configured three HTTP streaming sources into a cluster. The URLs of the first two hosts are wrong on purpose to demonstrate failing hosts. The streaming will begin from the third host and you can see what is happening in the box below the player.

Search engine friendly content

Events related to the cluster appear here:

The configuration is shown below. It listens to the onConnect and onConnectFailed events to show info of the connection attempts.

// a global variable that references our info box
var info = document.getElementById("info");

flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.4.swf", {
	log: { level: 'debug', filter: 'org.flowplayer.cluster.*' },
    plugins:  {

		// cluster plugin configuration
		cluster: {

			url: 'flowplayer.cluster-3.2.2.swf',

			// our hosts on the cluster
			hosts: [
				  // first two hosts will fail
				 'http://invalid.flowplayer.org/video',
				 'http://nonexistent.flowplayer.org/video',

				 // this one will answer (if the server is up)
				'http://vod01.netdna.com/vod/demo.flowplayer'
			],

			// callback method for connection attempt
			onConnect: function(host, index) {
				info.innerHTML += "attempting to connect: " + host + "<br />";
			},

			// callback method for connection failure
			onConnectFailed: function(host, index) {
				info.innerHTML += "connection failed to: " + host + "<br />";
			}
		}

    },

	 // use our cluster plugin as a "URL resolver"
    clip: {
        urlResolvers: 'cluster',

        onStart: function(clip) {
			  info.innerHTML += "clip started: " + clip.url;
        }
    }
});

Configuration

Here is a list of the configuration options:

property / datatype default description
hosts
array
The hosts that are part of the cluster. These should be base URLs for each host to be used together with the clip's URL. The complete URL will be formed by concatenating the host URL and the clip's URL.
connectTimeout
int
2000 Connection timeout for a single connection attempt, given in milliseconds. After this timeout has been reached, the connection attempt is considered a failure and the next host in the cluster is evaluated.
connectCount
int
3 Number of times to loop through all the hosts in the cluster before giving up.
failureExpiry
int
2000 The expiry time (in milliseconds) to wait before a failed server is attempted again. The failure timestamp is stored in the client browser and a new connection attempt is only attempted after this time has expired.
loadBalance
boolean
false When this is set to true the plugin accesses the configured hosts randomly providing the ability to balance the streaming load more evenly between each host to improve overall performance. If any of the hosts does not work, then another host is chosen.

Load balancing

The plugin can be set to randomly pick hosts from the cluster. This allows for simple load balancing completely controlled on the client side. This is achieved with the loadBalance property. Click on the splash image to see an example. It will randomly pick a host from the two alternatives.

Search engine friendly content

Clustering events appear here

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 in the end both servers will be loaded evenly. The load balancing is enabled with the 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.4.swf", {
	
	// configuration for the clustering plugin
	plugins:  {
		cluster: {
			url: 'flowplayer.cluster-3.2.2.swf',
			
			// two working hosts
			hosts: [
				'http://vod01.netdna.com/vod/demo.flowplayer',
				'http://video.flowplayer.org'
			],
			
			// 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;
        }
    }
	 
});

It's also possible to work with a combination of client-side and server-side load balancing. The server-side load balancing is usually done using a load balancer running in front of the RTMP or HTTP streaming servers.

Clustering RTMP servers

A cluster of RTMP servers is configured like this:

flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.4.swf", {

    clip: {
        // for FMS we don't use the file extension here
        url: 'Extremists',
        provider: 'rtmp',

        // the clustering plugin is configured as a connectionProvider
        // when used with RTMP
        connectionProvider: 'clustering'
    },

    plugins:  {
        // we don't need the netConnectionUrl here because it is
        // taken from the hosts array of the cluster
        rtmp: {
             url: 'flowplayer.rtmp.swf'
        },
        clustering: {
            url: 'flowplayer.cluster.swf',
            netConnectionUrl: 'rtmp://cyzy7r959.rtmphost.com/flowplayer',

            // Our hosts array contains the netConnectionUrls to the servers
            hosts: [
                {host:'rtmp://cyzy7r959.badhost1.com/flowplayer'},
                {host:'rtmp://cyzy7r959.badhost2.com/flowplayer'},
                {host:'rtmp://cyzy7r959.rtmphost.com/flowplayer'}
            ]
        }
    }
});

JavaScript API

Methods

method returns description
setLoadBalancing(value) Plugin Enables/disables load balancing. When enabled, the plugin randomly picks hosts from the cluster. For example: setLoadBalancing(true)

Events

Event When does it fire?
onConnect() Fires when the plugin starts a new connection attempt. The callback is fed with two arguments:
  • host the URL from the hosts list where the connection is attempted from.
  • hostIndex the index of the host in the hosts list.
onConnectFailed() Fires when a connection attempt has failed. The callback is fed with two arguments:
  • host the URL from the hosts list where the failure happened.
  • hostIndex the index of the host in the hosts list.
onFailed() Fires when all hosts in the cluster have failed. See also the connectCount option, that specifies how many times the hosts are evaluated before failing.

Download

flowplayer.cluster-3.2.2.swf just the working Flash file to get you going
flowplayer.cluster-3.2.2.zip working Flash file (swf) + README.txt and LICENCE.txt
flowplayer.cluster-3.2.2-src.zip source code

Please right-click and choose "Save link as..." (or similar)

See the version history for this tool.

NOTE We are no longer providing packed scripts. Althought they may have smaller file size they offer less performance than minified scripts. See details from JavaScript Library Loading Speed.

Found a bug?

If you encounter problems in this script, please send a bug report to the bug reporting forum. If you have a problematic page, including a direct URL to that page is by far the most effective way of helping us to find a bug.