In this blog post, we’re going to tell how to setup a Scalable Ant Media Server Cluster in Amazon Web Services. This solution that really cut the costs for projects that need scalable ultra low latency streaming. Let me explain how. Assume that your project needs scalable ultra low latency streaming. There are a few options to start.

  1. Implement your own ultra low latency solution.
  2. Use one of the Platform as a Service (PaaS) solutions.
  3. Use a scalable software solution that you can run on your own cloud. You’ll just use your own Infrastructure as a Service (IaaS) to create your streaming service.

Actually first option is something like inventing the wheel again. It likely takes long time according to your expertise.  Second option is ok if you have good amount of budget. The third option seems best in terms of low cost and full control. It just requires some experience in cloud.

Infrastructure as a Service is already rising

When you have your own scalable ultra low latency streaming service, then you can take advantage of several things. For instance, you likely have an agreement with your Infrastructure as a Service (IaaS) provider(AWS, Azure,…) about some discounts. So that you can use these discounts for your streaming service as well.  Another option is that you will have the full control to scaling your streamers and viewers. In other words, Infrastructure as a Service is already rising. Let it rise for you.

Let’s get started how to start your own scalable ultra low latency streaming service on AWS.

Getting Started for Ultra Low Latency Streaming Service on AWS

Here is the system outline

 

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 1

Let me give some brief definitions.

  • Load Balancer:  LB is the entrance point for the publishers and players. Load Balancer accepts the requests from publishers or players and forwards the requests to the available node in the cluster.
  • Origin Auto-Scalable Group: Nodes(Instances) in the origin group accepts the publish requests and ingest the incoming WebRTC stream. When an origin instance accepts a WebRTC stream, it saves the related information to the MongoDB Database Server.
    There may be one node or multiple node in origin group. It may even be manually or auto scalable. In our deployment, it’s auto-scalable in AWS.
  • Edge Auto-Scalable Group: Node(Instances) in the edge group accepts the play requests. Then it learns from MongoDB which origin node has the related stream. After that it gets the stream from related origin node and sends the stream to the player.
  • MongoDB Database Server: Ant Media Server uses MongoDB in clustering. Streams information are saved to MongoDB so that edge instances can learn any stream’s origin node.

Right now let’s start with installing MongoDB Server

Step 1: Install MongoDB Server

The procedure below shows how to start an instance in AWS EC2 service as well. In other words, if you have no experience about AWS, you can even install MongoDB Server as follows. If you know how to start an instance in AWS, just skip to “Install MongoDB to Your Instance”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 2

  • Click “Launch” Instance.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 3

  • Search for “Ubuntu” and Select “Ubuntu 16.04”.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 4

  • Choose Instance Type like m4.xlarge or m5.xlarge series. There are two points here.
    • First one is you may optionally choose a bigger instance according to your streaming load.
    • Second one don’t use any m5a instances because they have ARM architecture.

Then click “Review and Launch”.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 5

  • Click “Edit Security Groups” in the image.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 6

  • Add “22” and “27017” TCP ports as follows in the image. Warning is critical for security. We’ll restrict source into a VPC later. Just click “Review and Launch” .

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 7

  • In the coming window, Click “Launch” button again. Then it will ask to specify key file. Choose “Create new key pair” and click “Download Key Pair” button. After key file is downloaded. Click “Launch Instances”
    How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 8
  • Right now, your instances should be launching as shown in the image

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 9

  • Go to EC2 Instances and Click “Connect” button.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 10

  • It shows a dialog as follow and connect to instance via ssh

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 11

  • Right now, you should connect to your instance. To Connect your instance, open a terminal and run a command something like. Please change {YOUR_KEY_FILE} and {INSTANCE_PUBLIC_IP} with your own credentials. For our case, they are “ant.pem” and “ec2-35-159-50-16.eu-central-1.compute.amazonaws.com”

    ssh -i {YOUR_KEY_FILE} ubuntu@{INSTANCE_PUBLIC_IP}

Install MongoDB to Your Instance

  • After you get connected, run the following commands in order to install MongoDB to your instance
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
  • Open /etc/mongod.conf file with an editor like nano and change bind_ip value to 0.0.0.0  to let MongoDB accept connections in all interfaces and save it.

sudo nano /etc/mongod.conf

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 12

Press “Ctrl + X” to save the file.

  • Restart mongod and enable service.

sudo service mongod restart
sudo systemctl enable mongod.service

MongoDB installation is complete, just save your MongoDB instance’s local address somewhere. We will use it in later.

Step 2: Install Scalable Origin Group

  • Click “Auto Scaling > Launch Configurations” and Click “Create Launch Configurations”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 13

  • Click “AWS Marketplace” on the left side menu. Search for “Ant Media Server” and Choose the “Ant Media Server Enterprise” and Click “Select”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 14

  • Choose instance type, in our sample we choose m5.2xlarge. You can choose any instance type according to your project. After that click “Next: Configure details”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 15

  • In the coming window as shown in the image below,  We need to give name and set User data.
    • You can see the name field just under the Create Launch Configuration header. Give a name something like  “OriginGroup”
    • Then Click “Advanced Details” title. You will see the “User data” text area. Right now, copy the text below, change the “{MongoIP}” field with the MongoDB IP Address in the script and paste it to the “User data”.
    • After that Click “Skip to review”
#!/bin/bash
cd /usr/local/antmedia
./change_server_mode.sh cluster {MongoIP}

The form should be something like below

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 16

  • Click “Create Launch Configuration”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 17

  • After launch configuration is created successfully, Click the “Create an Auto Scaling Group using this Launch Configuration”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 18

 

  • Give a name to scaling group. We give “AMS-Origin-Group”  as a name and choose “eu-central-1a” subnet. We choose only one instance to let all instances appear in the same subnet for having better connectivity.  And then click “Configure Scaling Policies”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 19

  • Choose your scaling policy. In our sample below, our origin group will scale up to 10 instances by providing Average CPU Utilization with %60. Then Click Next and Next.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 20

  • Lastly, Review screen will come and click the “Create Auto Scaling group”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 21

Step 3: Install Scalable Edge Group

Installing scalable edge group almost same as scalable origin group.  Please go to Step 2: Install Scalable Origin Group and do the same things one more time. Just don’t forget to change some namings(for instance give group name as Edge Group) and configure scaling policy and instance type according to your needs. If you have any question or problem with this, please let us know through contact@antmedia.io

Step 4: Install Load Balancer

  • Click the “Load Balancings > Load Balancers”  on EC2 Service and Click the “Create” button under Application Load Balancer

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 22

  • Give a name to your Load Balancer. Choose both HTTP and HTTPS by clicking “Add listener”. The port settings should be like in the image below.
    Lastly, choose eu-central-1a and eu-central-1b for availability zones. Then Click “Next: Configure Security Groups”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 23

  • Choose your domain certificate from the screen. Then click “Next: Configure Security Groups” . (If you don’t know how to create certificate for ACM, please follow this guide. )

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 24

  • Create Security Group as shown in the image and then Click Next

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 25

  • Specify Routing as follows. Create a new target group and forward with HTTP through 5080 port

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 26

  • In the Register Targets group, do nothing, just proceed because we bind target later. Proceed to Review section and Click the Create button

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 27

Right now. All groups should be created, we just need to bind load balancer to the origin and edge scaling groups. Firstly, Go to the “Auto Scaling Groups” and Select the AMS Origin Group and Choose Edit in Actions drop down menu. Then choose the Origin-Target-Group in Target Group as follows in the image. Click “Save” button.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 28The setting above lets Origin Group be in “Origin-Target-Group” so that Load Balancer can forward requests to the Origin Group. Right now it’s time for Edge Group.   We assume that you already created AMS-Edge-Group in Step 3. So that right now just Create a Target from “Load Balancing > Target Groups” as follows

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 29

  • Then Go to AMS-Edge-Group in “Auto Scaling > Auto Scaling Groups” and Click the Edit item in the Actions button and add Edge-Target-Group as Target Group as in the image below

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 30

  • Here is the last items for Load Balancer.  Go to Load Balancer. Add new Listener for 5080 and 5443 that forward requests to Edge-Target-Group. Firstly Click “Add Listener”

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 31

  • Add Listener for HTTP(5080) and HTTPS(5443) as follows.

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 32

  • Click “Save” button. It returns the Load Balancer screen then Click “Add Listener” again and add HTTPS(5443) as in the image below

How to Setup Scalable Ultra Low Latency Streaming Cluster in AWS 33

  • Click “Save” button again.

 

Right now Everything is ok. Just let me give a brief information about the difference between publish and play. In our load balancer configuration, we forward HTTP(80) and HTTPS(443) to Origin Group and we forward HTTP(5080) and HTTPS(5443) to Edge Group. It means that we should connect 80 or 443 ports to publish and connect 5080 or 5443 to play streams. Otherwise, play requests goes to origin group and publish request goes to edge group and it’s likely create some performance issues according to your configurations.

In order to connect to your cluster just type your load balancer dns name or your own assigned dns name to your web browser and continue.

I hope this guide will help some guys to get started in clustering. It’s good to understand the general picture. Later, we have some plans to provide easier ways to install cluster in AWS. If you have any question, please let us know through contact@antmedia.io

 

[Total: 1    Average: 5/5]
Categories: Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *