Live stream metrics analysis
Live streaming has become a popular form of entertainment where streamers can interact with their audience in real time.
Overview
Not only do streamers want to keep a high view count, but they also want to maintain a high-quality stream to ensure the viewing experience is enjoyable for their audience.
There are numerous metrics to keep track of when sustaining a stable live stream. One of the most common metrics is how long the stream was frozen. Streamers and viewers do not want a stream frozen for long as it disrupts the experience.
In this tutorial, you will learn how to monitor live stream metrics, such as video quality and view count, using RisingWave. We have set up a demo cluster for this tutorial so you can easily try it out.
Prerequisites
- Ensure you have Docker and Docker Compose installed in your environment. Note that Docker Compose is included in Docker Desktop for Windows and macOS. If you use Docker Desktop, ensure it is running before launching the demo cluster.
- Ensure that the PostgreSQL interactive terminal,
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL.
Step 1: Launch the demo cluster
In the demo cluster, we packaged RisingWave and a workload generator. The workload generator will start to generate random traffic and feed them into Kafka as soon as the cluster is started.
First, clone the risingwave repository to the environment.
Now navigate to the integration_tests/livestream
directory and start the demo cluster from the docker compose file.
COMMAND NOT FOUND?
The default command-line syntax in Compose V2 starts with docker compose
. See details in the Docker docs.
If you’re using Compose V1, use docker-compose
instead.
Necessary RisingWave components will be started, including the compute node, metadata node, and MinIO. The workload generator will start to generate random data and feed them into Kafka topics. In this demo cluster, data of materialized views will be stored in the MinIO instance.
Now connect to RisingWave to manage data streams and perform data analysis.
Step 2: Connect RisingWave to data streams
Now that we have set up the data stream in Kafka (in JSON) using the demo cluster, we can connect to the streams with the following SQL statement. The data contains information regarding the video streaming metrics as well as the unique viewers of each stream.
RisingWave is connected to the streams but has not started to consume data yet. For data to be processed, we need to define materialized views. After a materialized view is created, RisingWave will consume data from the specified offset.
Step 3: Create materialized views
In this tutorial, we will create different materialized views that keep track of the video streaming performance and the viewer count.
Set up materialized view for live stream performance
The first materialized view will summarize the streaming performance for each stream every 10 minutes. To create it, we will use the tumble function to map each event into a 10-minute window and aggregate based on each room to calculate how long the stream was frozen, the average number of packets lost per second, and the average round-trip time.
We can query the results with the following SQL statement.
Here is an example result.
Set up materialized view for view counts
Next, we will set up two materialized views to keep track of view counts.
The first materialized view will track the number of unique viewers on the entire streaming site every minute. We will use the tumble function to map each event into a one-minute window and count the number of distinct viewers within each time window.
We can query the results with the following SQL statement.
Here is an example result.
The second materialized view will track each streamer’s unique viewers every minute. We will use the tumble function to map each event into a one-minute window and then group by the room_id to each streamer’s unique viewers.
We can query the results with the following SQL statement.
Here is an example result.
When you finish, run the following command to disconnect RisingWave.
Optional: To remove the containers and the data generated, use the following command.
Summary
In this tutorial, we learn:
- How to analyze video streaming metrics.
- How to set up a real-time dashboard to keep track of the number of unique viewers.
Was this page helpful?