{"id":19233765,"url":"https://github.com/ossrs/srs-bench","last_synced_at":"2025-10-19T04:09:19.109Z","repository":{"id":32576554,"uuid":"36159541","full_name":"ossrs/srs-bench","owner":"ossrs","description":"SB(SRS Bench) is a set of benchmark and regression test tools, for SRS and other media servers, supports HTTP-FLV, RTMP, HLS, WebRTC and GB28181.","archived":false,"fork":false,"pushed_at":"2025-03-13T00:19:01.000Z","size":14787,"stargazers_count":410,"open_issues_count":41,"forks_count":228,"subscribers_count":20,"default_branch":"feature/rtc","last_synced_at":"2025-04-04T16:06:22.052Z","etag":null,"topics":["benchmark","blackbox-testing","regression-testing","srs"],"latest_commit_sha":null,"homepage":"https://ossrs.net","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ossrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-24T06:32:55.000Z","updated_at":"2025-03-18T08:06:00.000Z","dependencies_parsed_at":"2024-06-18T19:57:37.621Z","dependency_job_id":"12dee8a8-5c3c-4cd0-b800-beab415b5512","html_url":"https://github.com/ossrs/srs-bench","commit_stats":{"total_commits":129,"total_committers":1,"mean_commits":129.0,"dds":0.0,"last_synced_commit":"aa029b492d0f588858e3e1ca51d64b9fe76d08b3"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-bench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-bench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-bench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossrs%2Fsrs-bench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ossrs","download_url":"https://codeload.github.com/ossrs/srs-bench/tar.gz/refs/heads/feature/rtc","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248489455,"owners_count":21112578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","blackbox-testing","regression-testing","srs"],"created_at":"2024-11-09T16:11:46.809Z","updated_at":"2025-10-19T04:09:19.098Z","avatar_url":"https://github.com/ossrs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# srs-bench\n\nSB(SRS Bench) is a set of benchmark and regression test tools, for SRS and other media servers, supports HTTP-FLV, RTMP,\nHLS, WebRTC and GB28181.\n\nFor RTMP/HLS/FLV benchmark, please use branch [master](https://github.com/ossrs/srs-bench/tree/master).\n\n## Usage\n\n下载代码和编译：\n\n```bash\ngit clone -b feature/rtc https://github.com/ossrs/srs-bench.git \u0026\u0026 \ncd srs-bench \u0026\u0026 make\n```\n\n\u003e Note: 依赖Go编译工具，建议使用 Go 1.21 及以上的版本。\n\n编译会生成下面的工具：\n\n* `./objs/srs_bench` 压测，模拟大量客户端的负载测试，支持SRS、GB28181和Janus三种场景。 \n* `./objs/srs_test` 回归测试(SRS)，SRS服务器的回归测试。\n* `./objs/srs_gb28181_test` 回归测试(GB28181)，GB服务器的回归测试。\n* `./objs/srs_blackbox_test` 黑盒测试(SRS)，SRS服务器的黑盒测试，也可以换成其他媒体服务器。\n\n\u003e Note: 查看工具的全部参数请执行`./objs/xx -h`\n\n有些场景，若需要编译和启动SRS:\n\n```bash\ngit clone https://github.com/ossrs/srs.git \u0026\u0026\ncd srs/trunk \u0026\u0026 ./configure --h265=on --gb28181=on \u0026\u0026 make \u0026\u0026\n./objs/srs -c conf/regression-test-for-clion.conf\n```\n\n\u003e Note: Use valgrind to check memory leak, please use `valgrind --leak-check=full ./objs/srs -c conf/regression-test-for-clion.conf \u003e/dev/null` to start SRS.\n\n具体场景，请按下面的操作启动测试。\n\n## Player for WHEP\n\n直播播放压测，一个流，很多个播放。\n\n首先，推流到SRS：\n\n```bash\nffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/live/livestream\n```\n\n然后，启动压测，比如100个：\n\n```bash\n./objs/srs_bench -sr webrtc://localhost/live/livestream -nn 100\n```\n\n## Publisher for WHIP\n\n直播或会议场景推流压测，一般会推多个流。\n\n首先，推流依赖于录制的文件，请参考[DVR](#dvr)。\n\n然后，启动推流压测，比如100个流：\n\n```bash\n./objs/srs_bench -pr webrtc://localhost/live/livestream_%d -sn 100 -sa a.ogg -sv v.h264 -fps 25\n```\n\n\u003e 注意：帧率是原始视频的帧率，由于264中没有这个信息所以需要传递。\n\n## Multiple WHIP or WHEP for RTC\n\n会议场景的播放压测，会多个客户端播放多个流，比如3人会议，那么就有3个推流，每个流有2个播放。\n\n首先，启动推流压测，比如3个流：\n\n```bash\n./objs/srs_bench -pr webrtc://localhost/live/livestream_%d -sn 3 -sa a.ogg -sv v.h264 -fps 25\n```\n\n然后，每个流都启动播放压测，比如每个流2个播放：\n\n```bash\n./objs/srs_bench -sr webrtc://localhost/live/livestream_%d -sn 3 -nn 2\n```\n\n\u003e 备注：压测都是基于流，可以任意设计推流和播放的流路数，实现不同的场景。\n\n\u003e 备注：URL的变量格式参考Go的`fmt.Sprintf`，比如可以用`webrtc://localhost/live/livestream_%03d`。\n\n\u003ca name=\"dvr\"\u003e\u003c/a\u003e\n## DVR for RTC Benchmark\n\n录制场景，主要是把内容录制下来后，可分析，也可以用于推流。\n\n首先，推流到SRS，参考[live](#player-for-live)。\n\n```bash\nffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/live/livestream\n```\n\n然后，启动录制：\n\n```bash\n./objs/srs_bench -sr webrtc://localhost/live/livestream -da a.ogg -dv v.h264\n```\n\n\u003e 备注：录制下来的`a.ogg`和`v.h264`可以用做推流。\n\n## RTC Plaintext\n\n压测RTC明文播放：\n\n首先，推流到SRS：\n\n```bash\nffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/live/livestream\n```\n\n然后，启动压测，指定是明文（非加密），比如100个：\n\n```bash\n./objs/srs_bench -sr webrtc://localhost/live/livestream?encrypt=false -nn 100\n```\n\n\u003e Note: 可以传递更多参数，详细参考SRS支持的参数。\n\n## Reconnecting Load Test\n\n建立连接和断开重连的压测，可以测试SRS在多个Source时是否有内存泄露问题，参考 [#3667](https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107)\n\nRTMP重连测试：\n\n```bash\nfor ((i=0;;i++)); do\n  ./objs/srs_bench -sfu=live -pr=rtmp://localhost/live${i}/stream -sn=1000 -cap=true; \n  sleep 10; \ndone\n```\n\nSRT重连测试：\n\n```bash\nfor ((i=0;;i++)); do\n  ./objs/srs_bench -sfu=live -pr='srt://127.0.0.1:10080?streamid=#!::'m=publish,r=live${i}/stream -sn=1000 -cap=true;\n  sleep 10; \ndone\n```\n\nWebRTC重连测试：\n\n```bash\nfor ((i=0;;i++)); do\n  ./objs/srs_bench -sfu=rtc -pr=webrtc://localhost/live${i}/livestream -sn=1000 -cap=true;\n  sleep 10; \ndone\n```\n\n## Regression Test\n\n回归测试需要先启动[SRS](https://github.com/ossrs/srs/issues/307)，支持WebRTC推拉流：\n\n```bash\n./objs/srs -c conf/regression-test-for-clion.conf\n```\n\n然后运行回归测试用例，如果只跑一次，可以直接运行：\n\n```bash\ngo test ./srs -mod=vendor -v -count=1\n```\n\n也可以用make编译出重复使用的二进制：\n\n```bash\nmake \u0026\u0026 ./objs/srs_test -test.v\n```\n\n\u003e Note: 注意由于pion不支持`DTLS 1.0`，所以SFU必须要支持`DTLS 1.2`才行。\n\n运行结果如下：\n\n```bash\n$ make \u0026\u0026 ./objs/srs_test -test.v\n=== RUN   TestRTCServerVersion\n--- PASS: TestRTCServerVersion (0.00s)\n=== RUN   TestRTCServerPublishPlay\n--- PASS: TestRTCServerPublishPlay (1.28s)\nPASS\n```\n\n可以给回归测试传参数，这样可以测试不同的序列，比如：\n\n```bash\ngo test ./srs -mod=vendor -v -count=1 -srs-server=127.0.0.1\n# Or\nmake \u0026\u0026 ./objs/srs_test -test.v -srs-server=127.0.0.1\n```\n\n可以只运行某个用例，并打印详细日志，比如：\n\n```bash\nmake \u0026\u0026 ./objs/srs_test -test.v -srs-log -test.run TestRtcBasic_PublishPlay\n```\n\n支持的参数如下：\n\n* `-srs-server`，RTC服务器地址。默认值：`127.0.0.1`\n* `-srs-stream`，RTC流地址，一般会加上随机的后缀。默认值：`/rtc/regression`\n* `-srs-timeout`，每个Case的超时时间，毫秒。默认值：`5000`，即5秒。\n* `-srs-publish-audio`，推流时，使用的音频文件。默认值：`avatar.ogg`\n* `-srs-publish-video`，推流时，使用的视频文件。默认值：`avatar.h264`\n* `-srs-publish-video-fps`，推流时，视频文件的FPS。默认值：`25`\n* `-srs-vnet-client-ip`，设置[pion/vnet](https://github.com/ossrs/srs-bench/blob/feature/rtc/vnet/example_test.go)客户端的虚拟IP，不能和服务器IP冲突。默认值：`192.168.168.168`\n\n其他不常用参数：\n\n* `-srs-log`，是否开启详细日志。默认值：`false`\n* `-srs-play-ok-packets`，播放时，收到多少个包认为是测试通过，默认值：`10`\n* `-srs-publish-ok-packets`，推流时，发送多少个包认为时测试通过，默认值：`10`\n* `-srs-https`，是否连接HTTPS-API。默认值：`false`，即连接HTTP-API。\n* `-srs-play-pli`，播放时，PLI的间隔，毫秒。默认值：`5000`，即5秒。\n* `-srs-dtls-drop-packets`，DTLS丢包测试，丢了多少个包算成功，默认值：`5`\n\n\u003e Note: 查看全部参数请执行`./objs/srs_test -h`\n\n\u003ca name=\"gb28181\"\u003e\u003c/a\u003e\n## GB28181 Test\n\n支持GB28181的压测，使用选项`-sfu gb28181`可以查看帮助：\n\n```bash\nmake \u0026\u0026 ./objs/srs_bench -sfu gb28181 --help\n```\n\n运行回归测试用例，更多命令请参考[Regression Test](#regression-test)：\n\n```bash\ngo test ./gb28181 -mod=vendor -v -count=1\n```\n\n也可以用make编译出重复使用的二进制：\n\n```bash\nmake \u0026\u0026 ./objs/srs_gb28181_test -test.v\n```\n\n支持的参数如下：\n\n* `-srs-sip`，SIP服务器地址。默认值：`tcp://127.0.0.1:5060`\n* `-srs-stream`，GB的user，即流名称，一般会加上随机的后缀。默认值：`3402000000`\n* `-srs-timeout`，每个Case的超时时间，毫秒。默认值：`11000`，即11秒。\n* `-srs-publish-audio`，推流时，使用的音频文件。默认值：`avatar.aac`\n* `-srs-publish-video`，推流时，使用的视频文件，注意：扩展名`.h264`表明编码格式为`AVC`，`.h265`表明编码格式为`HEVC`。默认值：`avatar.h264`\n* `-srs-publish-video-fps`，推流时，视频文件的FPS。默认值：`25`\n\n其他不常用参数：\n\n* `-srs-log`，是否开启详细日志。默认值：`false`\n\n\u003e Note: 查看全部参数请执行`./objs/srs_gb28181_test -h`\n\n## Blackbox Test\n\n使用FFmpeg作为客户端，对流媒体服务器SRS进行黑盒压测，完全黑盒的回归测试。\n\n运行回归测试用例，如果只跑一次，可以直接运行：\n\n```bash\ngo test ./blackbox -mod=vendor -v -count=1\n```\n\n也可以用make编译出重复使用的二进制：\n\n```bash\nmake \u0026\u0026 ./objs/srs_blackbox_test -test.v\n```\n\n由于黑盒测试依赖特殊的FFmpeg，可以在Docker中编译和启动：\n\n```bash\ndocker run --rm -it -v $(pwd):/g -w /g ossrs/srs:ubuntu20 bash\nmake \u0026\u0026 ./objs/srs_blackbox_test -test.v\n```\n\n\u003e Note: 依赖SRS二进制，当然也可以在这个Docker中编译SRS，具体请参考SRS的Wiki。\n\n支持的参数如下：\n\n* `-srs-binary`，每个测试用例都需要启动一个SRS服务，因此需要设置SRS的位置。默认值：`../../objs/srs`\n* `-srs-ffmpeg`，FFmpeg工具的位置，用来推流和录制。默认值：`ffmpeg`\n* `-srs-ffprobe`，ffprobe工具的位置，用来分析流的信息。默认值：`ffprobe`\n* `-srs-timeout`，每个Case的超时时间，毫秒。默认值：`64000`，即64秒。\n* `-srs-publish-avatar`，测试源文件路径。默认值：`avatar.flv`。\n* `-srs-ffprobe-duration`，每个Case的探测时间，毫秒。默认值：`16000`，即16秒。\n* `-srs-ffprobe-timeout`，每个Case的探测超时时间，毫秒。默认值：`21000`，即21秒。\n\n其他不常用参数：\n\n* `-srs-log`，是否开启详细日志。默认值：`false`\n* `-srs-stdout`，是否开启SRS的stdout详细日志。默认值：`false`\n* `-srs-ffmpeg-stderr`，是否开启FFmpeg的stderr详细日志。默认值：`false`\n* `-srs-dvr-stderr`，是否开启DVR的stderr详细日志。默认值：`false`\n* `-srs-ffprobe-stdout`，是否开启FFprobe的stdout详细日志。默认值：`false`\n\n由于每个黑盒的用例时间都很长，可以开启并行：\n\n```bash\n./objs/srs_blackbox_test -test.v -test.parallel 8\n```\n\n\u003e Note: 查看全部参数请执行`./objs/srs_blackbox_test -h`\n\n## GCOVR\n\n本机生成覆盖率时，我们使用工具[gcovr](https://gcovr.com/en/stable/guide.html)。\n\n在macOS上安装gcovr：\n\n```bash\npip3 install gcovr\n```\n\n在CentOS上安装gcovr：\n\n```bash\nyum install -y python2-pip \u0026\u0026\npip install lxml \u0026\u0026 pip install gcovr\n```\n\n## Janus\n\n支持Janus的压测，使用选项`-sfu janus`可以查看帮助：\n\n```bash\nmake \u0026\u0026 ./objs/srs_bench -sfu janus --help\n```\n\n首先需要启动Janus，推荐使用[janus-docker](https://github.com/winlinvip/janus-docker#usage):\n\n```bash\nip=$(ifconfig en0 inet|grep inet|awk '{print $2}') \u0026\u0026\nsed -i '' \"s/nat_1_1_mapping.*/nat_1_1_mapping=\\\"$ip\\\"/g\" janus.jcfg \u0026\u0026\ndocker run --rm -it -p 8080:8080 -p 8443:8443 -p 20000-20010:20000-20010/udp \\\n    -v $(pwd)/janus.jcfg:/usr/local/etc/janus/janus.jcfg \\\n    -v $(pwd)/janus.plugin.videoroom.jcfg:/usr/local/etc/janus/janus.plugin.videoroom.jcfg \\\n    registry.cn-hangzhou.aliyuncs.com/ossrs/janus:v1.0.7\n```\n\n\u003e 若启动成功，打开页面，可以自动入会：[http://localhost:8080](http://localhost:8080)\n\n模拟5个推流入会，可以在页面看到入会的流：\n\n```bash\nmake -j10 \u0026\u0026 ./objs/srs_bench -sfu janus \\\n  -pr webrtc://localhost:8080/2345/livestream \\\n  -sa avatar.ogg -sv avatar.h264 -fps 25 -sn 5\n```\n\n模拟5个拉流入会，只拉流不推流：\n\n```bash\nmake -j10 \u0026\u0026 ./objs/srs_bench -sfu janus \\\n  -sr webrtc://localhost:8080/2345/livestream \\\n  -nn 5\n```\n\n## Install LIBSRT\n\n我们使用 [srtgo](https://github.com/Haivision/srtgo) 库测试SRT协议，需要安装libsrt库，\n参考[macOS](https://github.com/Haivision/srt/blob/master/docs/build/build-macOS.md)：\n\n```bash\nbrew install srt\n```\n\n如果是Ubuntu，可以参考[Ubuntu](https://github.com/Haivision/srt/blob/master/docs/build/package-managers.md):\n\n```bash\napt-get install -y libsrt\n```\n\n安装完libsrt后，直接编译srs-bench即可：\n\n```bash\nmake\n```\n\n## Ubuntu Docker\n\n如果使用Ubuntu编译，推荐使用 `ossrs/srs:ubuntu20` 作为镜像编译，已经编译了openssl和libsrt，启动容器：\n\n```bash\ndocker run --rm -it -v $(pwd):/g -w /g ossrs/srs:ubuntu20 make\n```\n\n## GoLand\n\n使用GoLand编译和调试时，需要设置libsrt的环境变量，首先可以使用brew获取路径：\n\n```bash\nbrew --prefix srt\n#/opt/homebrew/opt/srt\n```\n\n然后在GoLand中，编辑配置 `Edit Configurations`，添加环境变量：\n\n```bash\nCGO_CFLAGS=-I/opt/homebrew/opt/srt/include;CGO_LDFLAGS=-L/opt/homebrew/opt/srt/lib -lsrt\n```\n\n\u003e Note: 特别注意的是，CGO_LDFLAGS是可以有空格的，不能使用字符串，否则找不到库。\n\n2021.01, Winlin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossrs%2Fsrs-bench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fossrs%2Fsrs-bench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossrs%2Fsrs-bench/lists"}