ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.43k stars 5.35k forks source link

Forward and Cluster. #4079

Closed HeeJoon-Kim closed 3 months ago

HeeJoon-Kim commented 3 months ago

Strictly speaking, this is not a bug report but rather a question.

When the "forward" function is utilized, the CPU usage on the Master is greater than on the Slave.

I intended to use "forward" for load balancing by [stream] based on backend directives, and I expected the Master to perform only forwarding, resulting in very low CPU usage.

When handling 60 RTMP streams, the CPU usage on the Master is triple that of the Slave. Additionally, the Slave is responsible for creating HLS files.

image

Here is Master and Slave configuration.

[Master]

listen              1935;
max_connections     1000;
pid                 ./objs/srs.master.pid;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    forward {
        enabled on;
        backend http://127.0.0.1:9000/;
    }
}

[Slave]

listen              19350;
max_connections     1000;
pid                 ./objs/srs.slave.pid;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    hls {
        enabled         on;
        hls_ctx         off;
        hls_ts_ctx      off;
        hls_fragment    5;
        hls_window      30;
        hls_wait_keyframe   off;
        hls_vcodec      vn;
        hls_dts_directly    on;
        hls_path        ./objs/nginx/html;
        hls_m3u8_file   [app]/[stream]/index.m3u8;
        hls_ts_file     [app]/[stream]/[seq].ts;
    }
}

Is it correct that the Master handles more load than the Slave?

Secondly, when implementing an Origin cluster and performing RTMP Push to the Edge, even when the Origin generates HLS, the Edge consumes more CPU than the Origin cluster. Is this situation also accurate?

The environment involves multiple [streams within the same [app], and each [stream] updates the m3u8 file with DISCONTINUITY based on playlist playback.

When using REUSE PORT to generate HLS, different SRS processes encounter errors during cleanup of old ts files. And, the sequence number does not increase correctly, and sometimes the segment is assigned to a different process, resulting in the forced deletion of the last ts file.

For this structure, could you please advise on the best approach? Thank you! 😊

TRANS_BY_GPT4