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.75k stars 5.28k forks source link

Unexpected load on idle #3907

Open bugsyb opened 6 months ago

bugsyb commented 6 months ago

SRS v6.0-d3 & v5.0-b7 (just the two tested) present unexpected load of ~1-2% load whilst doing nothing - straight after start in Docker container with docker.conf config. Not the best comparison though both apache2 and nginx regardless of configs, whilst doing nothing do not show any load.

Expectations - for server doing nothing, it should not show that much if any load.

winlinvip commented 6 months ago

Is the coroutine mechanism of SRT causing the issue? Please compile SRS using the following method:

./configure --srt=off && make && ./objs/srs -c conf/srs.conf

Then try starting it again to see if the CPU usage has disappeared.

TRANS_BY_GPT4

bugsyb commented 6 months ago

Looks tiny bit better. It floats now between 0.4 - 0.7 (top with 5s refresh window).

Looking at strace (with logging at Warn) it just does this:

clock_gettime(CLOCK_REALTIME, {tv_sec=1702559525, tv_nsec=329327511}) = 0
epoll_wait(3, [], 4096, 513)            = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559525, tv_nsec=844217595}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559526, tv_nsec=845797888}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559527, tv_nsec=847338966}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559528, tv_nsec=849846968}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559529, tv_nsec=851922149}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559530, tv_nsec=854225296}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559531, tv_nsec=855834566}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559532, tv_nsec=858490140}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559533, tv_nsec=861310884}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559534, tv_nsec=864250506}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559535, tv_nsec=868192429}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559536, tv_nsec=871517187}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559537, tv_nsec=873906138}) = 0

If it runs with default logging (which gives stats on CPU) then it is a bit higher load and additional logging calls:

clock_gettime(CLOCK_REALTIME, {tv_sec=1702559462, tv_nsec=472663350}) = 0
epoll_wait(3, [], 4096, 327)            = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559462, tv_nsec=801016689}) = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559462, tv_nsec=801361000}) = 0
getpid()                                = 1
write(1, "[2023-12-14 13:11:02.801][INFO]["..., 72) = 72
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559463, tv_nsec=805329118}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559464, tv_nsec=807614677}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559465, tv_nsec=814963306}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559466, tv_nsec=818838109}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559467, tv_nsec=821455542}) = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559467, tv_nsec=821949487}) = 0
getpid()                                = 1
write(1, "[2023-12-14 13:11:07.821][INFO]["..., 72) = 72
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559468, tv_nsec=826818457}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559469, tv_nsec=829454296}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559470, tv_nsec=833662800}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559471, tv_nsec=836057696}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559472, tv_nsec=838723143}) = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559472, tv_nsec=839527813}) = 0
getpid()                                = 1
write(1, "[2023-12-14 13:11:12.839][INFO]["..., 72) = 72
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559473, tv_nsec=844363584}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559474, tv_nsec=847601675}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559475, tv_nsec=851281702}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559476, tv_nsec=852959777}) = 0
epoll_wait(3, [], 4096, 1000)           = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1702559477, tv_nsec=854501129}) = 0

Unsure why it calls clock_gettime that often.

Thanks for looking into this.