Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oryx Helm chart impl nginx-hls-cdn #5

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

suzp1984
Copy link

@suzp1984 suzp1984 commented Jul 19, 2024

Background

ref https://github.com/ossrs/oryx/tree/main/scripts/nginx-hls-cdn#nginx-hls-cdn

The commit is the k8s helm chart implementation of nginx-hls-cdn. Inside a k8s cluster, deploy a oryx pod and a autoscale nginx pods that provide hls server to the frontend.

How to Install

  1. download this repo;
  2. `helm install oryx ./oryx-nginx-hls;
  3. wait the containers download and pods deployed to k8s cluster;
  4. check pod status by kubectl get pods, and k8s services by kubectl get services;
  5. visit oryx front end by web browser: http://localhost:2080/mgmt/ (replace the localhost with the k8s service ip);
  6. enable HLS high performance mode and HLS Low Latency if you want to, by this path in above frontend webui: System -> HLS.
  7. push the video stream to the srs server;
  8. play HLS stream by the k8s service ip of the nginx LoadBalancer. (check kubectl get services) e.g. ffplay -i http://127.0.0.1/live/livestream.m3u8

How to do benchmark in your local pc?

  1. scripts to publish 50 streams to oryx or srs.
#!/bin/bash
for ((i=1;i<=50;i++)); 
do 
   # publish rtmp stream
   echo $i
   ffmpeg -nostdin -loglevel quiet -re -i trunk/doc/source.flv -c copy -f flv rtmp://localhost/live/livestream${i}?secret=fec73e1a68b84dc486240d9a9f952879 2>/dev/null &
done

the trunk/doc/source.flv is the test video source located at srs
the secret token is come from the oryx, check the oryx web UI.

  1. script to pull 1000 hls streams from nginx cache.
#!/bin/bash
for ((i=1;i<=1000;i++)); 
do 
    # generate random number in range [1-50], represent which stream.
    r=`shuf -i 1-50 -n 1`
    echo $r
    ffmpeg -nostdin -loglevel quiet -i http://127.0.0.1/live/livestream${r}.m3u8 -f null - &
done

There is a k8s job to run this script in the cloud for the testing purpose.
https://gist.github.com/suzp1984/cc7d21e00b142c6f83a28d709b9954d3

apiVersion: batch/v1
kind: Job
metadata:
  name: ffmpeg-pull-test
spec:
  ttlSecondsAfterFinished: 120
  template:
    spec:
      containers:
      - name: ffmpeg
        image: "ossrs/oryx:v5.15.20"
        imagePullPolicy: IfNotPresent
        command:
        - bash
        - -c
        - |-
          echo "pull live streams by ffmpeg"
          echo "start 500 ffmpeg processes to pull streams"
          for ((i=1;i<=500;i++)); 
          do 
            # generate random number in range [1-50], represent which stream.
            r=`shuf -i 1-50 -n 1`
            echo $r
            ffmpeg -nostdin -loglevel quiet -i http://127.0.0.1/live/livestream${r}.m3u8 -f null - &
          done
          
          while true; do
            sleep 1
            if [[ $(ps aux |grep ffmpeg |grep -v grep |grep -v usr |grep -q ffmpeg || echo no) == no ]]; then
              echo "all ffmpeg process done"
              break
            fi
          done
          echo "complete ffmpeg job"
      restartPolicy: Never
  backoffLimit: 4
  1. monitor pods metric
    kubectl top pod and kubectl top node

@suzp1984 suzp1984 force-pushed the feature/oryx-nginx-cache-hls branch from d3d77fd to e3ff597 Compare July 20, 2024 07:46
suzp1984 added 5 commits July 22, 2024 01:15
1. use ENV to get service ip address;
2. let http cache path configurable;
The container port is not configurable, it must be 80 for default nginx
server. Ingress don't compatible with multi service with port 80;
1. fix storageClassName not exit bug, let it configurable.
2. accessModes set to ReadWriteMany.
3. PVC add volumeName: bind PVC with the PV.
4. PV and PVC rename: srs-pv -> oryx-pv.
@suzp1984 suzp1984 force-pushed the feature/oryx-nginx-cache-hls branch from aae0ce8 to 59c3e1e Compare August 28, 2024 14:44
@suzp1984 suzp1984 force-pushed the feature/oryx-nginx-cache-hls branch from 59c3e1e to 9b03101 Compare August 28, 2024 14:53
@suzp1984 suzp1984 force-pushed the feature/oryx-nginx-cache-hls branch from e281ab5 to 514fa08 Compare September 2, 2024 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant