ossrs / srs

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

Thread: CircuitBreaker should support multiple threading for SRT. #3928

Open winlinvip opened 5 months ago

winlinvip commented 5 months ago

Describe the bug When the SRS operates in multi-threaded mode, such as with the SRT protocol, in addition to the main thread of SRS, two additional worker threads are initiated. When the overall CPU usage reaches 100%, SRS accounts for approximately 40% of the usage, while the two SRT threads account for about 50%. At this point, a circuit breaker mechanism is triggered, resulting in packet loss.

Version SRS 6.0

To Reproduce Steps to reproduce the behavior:

  1. Benchmark SRS via SRT.
  2. Use top -H $(pidof srs) to check CPU usage of each threads of SRS.
  3. When total CPU is 100%, SRS CPU is about 40%, the circuit breaker works and drop packets.

Expected behavior In multi-threaded mode, the circuit breaker should be triggered based on the CPU usage of the highest-utilized thread, rather than the total CPU usage.

Screenshots

image

TRANS_BY_GPT4

xiaozhihong commented 5 months ago

Attempt to acquire only the main thread's CPU usage as the basis for circuit breaker decisions.

TRANS_BY_GPT4

winlinvip commented 5 months ago

Assessing the load on a multithreaded program is challenging; one should evaluate the CPU usage of the thread with the highest load. Merely considering the CPU usage of the primary thread of the SRS may be insufficient, as high load on the SRT's threads can also lead to issues.

TRANS_BY_GPT4