Relays and Autoscaling Logic

When you create a launch configuration policy, this includes setting a connectionCapacity. Autoscaling uses this and the Alarm Threshold to determine when to scale up origin and edge server nodes. Each broadcaster is a connection on the origin server, and each subscriber is a connection on the edge server.

Origin and Edge Nodes

In a simple nodegroup/cluster, the origin and edge roles are pretty straight forward:

  • Broadcasters are directed to the origin server(s)
  • Subscribers are directed to the edge server(s)

Example 1: Nodegroup created with one origin and one edge server.

  • origin server connectionCapacity set to 50. Alarm threshold set to 60% (default).
  • edge server connectionCapacity set to 400. Alarm threshold set to 60% (default).

Let's say this is a one-to-many scenario. So, one broadcaster/one stream.

When there are 241 subscribers, the stream manager will add a second edge server. New connections will be directed to whichever edge server has the least connections. To start, that will definitely be the new edge server, but some of the original subscribers might drop off, and at some point the traffic will be more evenly balanced between the two edge nodes. If at some point the second edge server reaches 241 connections, then a third edge server will be spun up, and so on until you reach the maxLimit defined in your scaling policy. When your subscribers drop off, or your broadcast ends, the nodegroup will scale back down, ultimately to the defined minLimit.

If the edge server reaches 400 connections, the defined connectionCapacity, the stream manager will no longer send any new connections to that server.

Note: edge servers will not be spun down if they have any active connections.

Relay Nodes

Relay servers are recommended for the use case of one (or a few) broadcasters to many subscribers. They are basically repeaters which boost the signal of the broadcast.

Relay nodes do not scale (neither up nor down). When you set the maxLimit for your edge servers, you should divide that by your edge connectionCapacity to determine the number of relay servers that you will need, and then set that as your minimum number of relays for your initial cluster configuration.

Example 2: As with the above, this is a one to many scenario, but it's for a large event. One broadcaster/one stream, but over 1,000,000 subscribers.

  • origin server connectionCapacity set to 50.
  • edge server connectionCapacity set to 400.
  • Given the connection capacity of the edges, we would need 2,500 edge servers to support 1,000,000 subscribers. 2,500/400=6.25, so we will want to have 7 relay servers in total.

NOTE: the relay server still needs to be set up with a defined connection capacity, even though that is not used.

Launch Configuration Example

POST

https://streammanager.com/streammanager/api/3.1/admin/configurations/launchconfig?accessToken=xyz123

{
    "launchconfig": {
      "name": "oer-release560",
      "description": "origin edge relay",
      "image": "ami-release-5.6.0",
      "version": "0.0.3",

      "targets": {
          "target": [
        {
          "role": "origin",
          "instanceType": "c5.large",
          "connectionCapacity": "50"
        },
        {
          "role": "edge",
          "instanceType": "c5.large",
          "connectionCapacity": "400"
        },
        {
          "role": "relay",
          "instanceType": "c5.large",
          "connectionCapacity": "400"
        }
         ]
        },

        "properties": {
          "property": [
            {
              "name": "property-name",
              "value": "property-value"
            }
          ]
        },
        "metadata": {
          "meta": [
            {
              "key": "meta-name",
              "value": "meta-value"
            }
          ]
        }
      }}

Scale Policy Example

POST

https://streammanager.com/streammanager/api/3.1/admin/configurations/scalepolicy?accessToken=xyz123

{
      "policy": {
          "name": "largeevent01",
          "description": "3rd generation scale policy file with one each origin edge relay",
          "type": "com.red5pro.services.autoscaling.model.ScalePolicyMaster",
          "version": "0.0.3",
          "targets": {
              "region": [
                  {
                      "name": "default",
                      "target": [
                          {
                              "role": "edge",
                              "estimatedWarmUpTime": 150000,
                              "maxLimit": 2500,
                              "scaleAdjustment": 1,
                              "coolDownPeriod": 180000,
                              "minLimit": 100
                          },
                          {
                              "role": "origin",
                              "estimatedWarmUpTime": 150000,
                              "maxLimit": 100,
                              "scaleAdjustment": 1,
                              "coolDownPeriod": 180000,
                              "minLimit": 2
                          },
                                                    {
                              "role": "relay",
                              "estimatedWarmUpTime": 150000,
                              "maxLimit": 7,
                              "scaleAdjustment": 1,
                              "coolDownPeriod": 180000,
                              "minLimit": 7
                          }
                      ]
                  }
                      ]
                  }
      }
  }

Then create a nodegroup based on those policies

POST:

https://streammanager.com/streammanager/api/3.1/admin/nodegroup?accessToken=xyz123

{
"regions": [
 "us-east-1"
 ],
 "launchConfig": "oer-release560",
 "scalePolicy": "largeevent01"
}

Initiate the nodegroup by adding an origin and wait for all of the nodes to be inservice before broadcasting.