-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Improve file writer performance by fwrite with cache. v5.0.133 #3308
Conversation
55dce2c
to
bc381a0
Compare
By WinlinI remember why "write" is used instead of "fwrite". It's because "st_write" can also write files, and it is a non-blocking operation. So actually, using "fwrite" from libc has better performance, but there are two issues that need to be discussed:
By John
By Bluestn
nginx does not use epoll to support file read/write, but instead uses aio. By Chen YuIt's not that epoll doesn't support it, it's that even ext4 hasn't implemented the poll callback, so it can't be achieved. The implementation of poll is required for it to be used with select/poll/epoll. Another issue with The advantages of By WinlinThe main purpose of Implementing it yourself is also a solution. Creating a thread is also considered as a final solution. However, you can also use fwrite within the thread. The main issue with threads currently is that cygwin64 SRT crashes. This problem needs to be resolved before creating threads.
|
Benchmark data:
Run SRS for HLS: env SRS_LISTEN=1935 SRS_DAEMON=off SRS_SRS_LOG_TANK=console SRS_HTTP_API_ENABLED=on \
SRS_VHOST_HLS_ENABLED=on ./objs/srs -e Run SRS for DVR: env SRS_LISTEN=1935 SRS_DAEMON=off SRS_SRS_LOG_TANK=console SRS_HTTP_API_ENABLED=on \
SRS_VHOST_DVR_ENABLED=on ./objs/srs -e Publish 100 streams by srs-bench: ./objs/sb_rtmp_publish -i doc/source.200kbps.768x320.flv -c 100 -r rtmp://127.0.0.1:1935/live/livestream_{i} Publish another 200 streams: ./objs/sb_rtmp_publish -i doc/source.200kbps.768x320.flv -c 200 -r rtmp://127.0.0.1:1935/live/livestream2_{i} |
9c4996c
to
7a646f8
Compare
7a646f8
to
49345b6
Compare
49345b6
to
e92ac94
Compare
…3308) * SrsFileWriter leverages libc buffer to boost dvr write speed. * Refactor SrsFileWriter to use libc file functions mockable * Add utest and refine code. Co-authored-by: winlin <[email protected]> PICK 25eb21e
I found srs dvr bottleneck while doing dvr stress test with many concurrent streams pushing to srs.
with perf flame graph's help, I found there are so many file write ops which consumed so many cpu time.
And I tracked the dvr module code, and found the SrsFileWriter use unix system file operation functions including open/write/lseek/close, it has no buffer mechanism in it, and every write op will lead to a new system call.
With this analysis, I used corresponding libc file operation functions to implement the SrsFileWriter, and use setvbuf with 65536 bytes buffer to enable the libc buffer mechanism, as i wished, the cpu usage rate drop down very obviously.
the following is the graph before and after the performance tuning.
before tuning:
after tuning: