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

Live: Limit cached max frames by gop_cache_max_frames #3236

Merged
merged 10 commits into from
Nov 22, 2022

Conversation

bluestn
Copy link
Contributor

@bluestn bluestn commented Nov 10, 2022

Use gop_cache_max_frames to limit the max frames which can be cached by gop cache, to keep srs from run out of memory while some malicious stream pusher never send any Key frames.

trunk/conf/srs.conf Outdated Show resolved Hide resolved
@bluestn
Copy link
Contributor Author

bluestn commented Nov 11, 2022

OK, modified as you pointed out. thank u.

How to verify this patch can work?

  1. find a flv video which is long enough encoded with avc/aac.
  2. use the flv key frame remove tool (https://github.com/bluestn/flv_remove_keyframe) to remove the flv key frames.
git clone https://github.com/bluestn/flv_remove_keyframe.git
mkdir -p flv_remove_keyframe/build
cd flv_remove_keyframe/build
cmake ..
make
cp ~/git/srs/trunk/doc/source.flv .
./flv_remove_keyframe source.flv
  1. use command to push the flv file to srs server.
ffmpeg -re -i source_no_keyframe.flv -c copy -f flv rtmp://localhost/live/livestream 
  1. without this patch, and when gop_cache is on, we can easily see that srs server will cache more and more frames in the gop_cache, and finally oom sooner or later.
    and after this patch applied, gop_cache will be kept no more than the frames set by gop_cache_max_frames.

@winlinvip
Copy link
Member

winlinvip commented Nov 22, 2022

Verified, it works! 👍

Before this patch, the gop cache increases:
dispatch cached gop success. count=4244, duration=62760

After this patch, we will clear the gop cache:
Gop cache exceed max frames=250, total=251, videos=93, aalvc=1

And the memory is ok now.

@winlinvip winlinvip changed the title Limit max frames in gop cache by gop_cache_max_frames Live: Limit cached max frames by gop_cache_max_frames Nov 22, 2022
@winlinvip winlinvip force-pushed the feature_gop_cache_max_frames branch from 0809a99 to 463f15c Compare November 22, 2022 04:00
@winlinvip winlinvip force-pushed the feature_gop_cache_max_frames branch from 463f15c to 0bd96ed Compare November 22, 2022 04:31
@winlinvip winlinvip merged commit ec76512 into ossrs:develop Nov 22, 2022
winlinvip added a commit to winlinvip/srs that referenced this pull request Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants