Skip to content

Commit 1f9309a

Browse files
winlinvipduiniuluantanqinsuzp1984
authored
SmartPtr: Support load test for source by srs-bench. v6.0.130 (#4097)
1. Add live benchmark support in srs-bench, which only connects and disconnects without any media transport, to test source creation and disposal and verify source memory leaks. 2. SmartPtr: Support cleanup of HTTP-FLV stream. Unregister the HTTP-FLV handler for the pattern and clean up the objects and resources. 3. Support benchmarking RTMP/SRT with srs-bench by integrating the gosrt and oryx RTMP libraries. 4. Refine SRT and RTC sources by using a timer to clean up the sources, following the same strategy as the Live source. --------- Co-authored-by: Haibo Chen <[email protected]> Co-authored-by: Jacob Su <[email protected]>
1 parent e3d74fb commit 1f9309a

File tree

508 files changed

+6774
-3268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

508 files changed

+6774
-3268
lines changed

trunk/3rdparty/srs-bench/Makefile

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1-
.PHONY: help default clean bench test
1+
.PHONY: help default clean bench pcap test all
22

33
default: bench test
44

55
clean:
66
rm -rf ./objs
77

8+
all: bench test pcap test
9+
810
#########################################################################################################
911
# SRS benchmark tool for SRS, janus, GB28181.
1012
./objs/.format.bench.txt: *.go janus/*.go ./objs/.format.srs.txt ./objs/.format.gb28181.txt
1113
gofmt -w *.go janus
1214
mkdir -p objs && echo "done" > ./objs/.format.bench.txt
1315

14-
bench: ./objs/srs_bench ./objs/pcap_simulator
16+
bench: ./objs/srs_bench
17+
18+
UNAME_S := $(shell uname -s)
19+
ifeq ($(UNAME_S),Darwin)
20+
SRT_PREFIX := $(shell brew --prefix srt)
21+
CGO_CFLAGS := -I$(SRT_PREFIX)/include
22+
CGO_LDFLAGS := -L$(SRT_PREFIX)/lib -lsrt
23+
else ifeq ($(UNAME_S),Linux)
24+
CGO_CFLAGS := -I/usr/local/include
25+
CGO_LDFLAGS := -L/usr/local/lib -lsrt -L/usr/local/ssl/lib -lcrypto -lstdc++ -lm -ldl
26+
endif
1527

16-
./objs/srs_bench: ./objs/.format.bench.txt *.go janus/*.go srs/*.go vnet/*.go gb28181/*.go Makefile
17-
go build -mod=vendor -o objs/srs_bench .
28+
./objs/srs_bench: ./objs/.format.bench.txt *.go janus/*.go srs/*.go vnet/*.go gb28181/*.go live/*.go Makefile
29+
CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -mod=vendor -o objs/srs_bench .
1830

1931
#########################################################################################################
2032
# For all regression tests.
@@ -35,6 +47,8 @@ test: ./objs/srs_test ./objs/srs_gb28181_test ./objs/srs_blackbox_test
3547
gofmt -w pcap
3648
mkdir -p objs && echo "done" > ./objs/.format.pcap.txt
3749

50+
pcap: ./objs/pcap_simulator
51+
3852
./objs/pcap_simulator: ./objs/.format.pcap.txt pcap/*.go Makefile
3953
go build -mod=vendor -o ./objs/pcap_simulator ./pcap
4054

@@ -59,9 +73,10 @@ test: ./objs/srs_test ./objs/srs_gb28181_test ./objs/srs_blackbox_test
5973
#########################################################################################################
6074
# Help menu.
6175
help:
62-
@echo "Usage: make [default|bench|test|clean]"
76+
@echo "Usage: make [default|bench|pcap|test|clean]"
6377
@echo " default The default entry for make is bench+test"
6478
@echo " bench Make the bench to ./objs/srs_bench"
79+
@echo " pcap Make the pcap simulator to ./objs/pcap_simulator"
6580
@echo " test Make the test tool to ./objs/srs_test and ./objs/srs_gb28181_test ./objs/srs_blackbox_test"
6681
@echo " clean Remove all tools at ./objs"
6782

trunk/3rdparty/srs-bench/README.md

+83-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ git clone -b feature/rtc https://github.com/ossrs/srs-bench.git &&
1414
cd srs-bench && make
1515
```
1616

17+
> Note: 依赖Go编译工具,建议使用 Go 1.17 及以上的版本。
18+
1719
编译会生成下面的工具:
1820

1921
* `./objs/srs_bench` 压测,模拟大量客户端的负载测试,支持SRS、GB28181和Janus三种场景。
@@ -33,7 +35,7 @@ cd srs/trunk && ./configure --h265=on --gb28181=on && make &&
3335

3436
具体场景,请按下面的操作启动测试。
3537

36-
## Player for Live
38+
## Player for WHEP
3739

3840
直播播放压测,一个流,很多个播放。
3941

@@ -49,7 +51,7 @@ ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/
4951
./objs/srs_bench -sr webrtc://localhost/live/livestream -nn 100
5052
```
5153

52-
## Publisher for Live or RTC
54+
## Publisher for WHIP
5355

5456
直播或会议场景推流压测,一般会推多个流。
5557

@@ -63,7 +65,7 @@ ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/
6365

6466
> 注意:帧率是原始视频的帧率,由于264中没有这个信息所以需要传递。
6567
66-
## Multipel Player or Publisher for RTC
68+
## Multiple WHIP or WHEP for RTC
6769

6870
会议场景的播放压测,会多个客户端播放多个流,比如3人会议,那么就有3个推流,每个流有2个播放。
6971

@@ -84,7 +86,7 @@ ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/
8486
> 备注:URL的变量格式参考Go的`fmt.Sprintf`,比如可以用`webrtc://localhost/live/livestream_%03d`
8587
8688
<a name="dvr"></a>
87-
## DVR for Benchmark
89+
## DVR for RTC Benchmark
8890

8991
录制场景,主要是把内容录制下来后,可分析,也可以用于推流。
9092

@@ -120,6 +122,37 @@ ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/
120122

121123
> Note: 可以传递更多参数,详细参考SRS支持的参数。
122124
125+
## Reconnecting Load Test
126+
127+
建立连接和断开重连的压测,可以测试SRS在多个Source时是否有内存泄露问题,参考 [#3667](https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107)
128+
129+
RTMP重连测试:
130+
131+
```bash
132+
for ((i=0;;i++)); do
133+
./objs/srs_bench -sfu=live -pr=rtmp://localhost/live${i}/stream -sn=1000 -cap=true;
134+
sleep 10;
135+
done
136+
```
137+
138+
SRT重连测试:
139+
140+
```bash
141+
for ((i=0;;i++)); do
142+
./objs/srs_bench -sfu=live -pr='srt://127.0.0.1:10080?streamid=#!::'m=publish,r=live${i}/stream -sn=1000 -cap=true;
143+
sleep 10;
144+
done
145+
```
146+
147+
WebRTC重连测试:
148+
149+
```bash
150+
for ((i=0;;i++)); do
151+
./objs/srs_bench -sfu=rtc -pr=webrtc://localhost/live${i}/livestream -sn=1000 -cap=true;
152+
sleep 10;
153+
done
154+
```
155+
123156
## Regression Test
124157

125158
回归测试需要先启动[SRS](https://github.com/ossrs/srs/issues/307),支持WebRTC推拉流:
@@ -329,4 +362,50 @@ make -j10 && ./objs/srs_bench -sfu janus \
329362
-nn 5
330363
```
331364

365+
## Install LIBSRT
366+
367+
我们使用 [srtgo](https://github.com/Haivision/srtgo) 库测试SRT协议,需要安装libsrt库,
368+
参考[macOS](https://github.com/Haivision/srt/blob/master/docs/build/build-macOS.md)
369+
370+
```bash
371+
brew install srt
372+
```
373+
374+
如果是Ubuntu,可以参考[Ubuntu](https://github.com/Haivision/srt/blob/master/docs/build/package-managers.md):
375+
376+
```bash
377+
apt-get install -y libsrt
378+
```
379+
380+
安装完libsrt后,直接编译srs-bench即可:
381+
382+
```bash
383+
make
384+
```
385+
386+
## Ubuntu Docker
387+
388+
如果使用Ubuntu编译,推荐使用 `ossrs/srs:ubuntu20` 作为镜像编译,已经编译了openssl和libsrt,启动容器:
389+
390+
```bash
391+
docker run --rm -it -v $(pwd):/g -w /g ossrs/srs:ubuntu20 make
392+
```
393+
394+
## GoLand
395+
396+
使用GoLand编译和调试时,需要设置libsrt的环境变量,首先可以使用brew获取路径:
397+
398+
```bash
399+
brew --prefix srt
400+
#/opt/homebrew/opt/srt
401+
```
402+
403+
然后在GoLand中,编辑配置 `Edit Configurations`,添加环境变量:
404+
405+
```bash
406+
CGO_CFLAGS=-I/opt/homebrew/opt/srt/include;CGO_LDFLAGS=-L/opt/homebrew/opt/srt/lib -lsrt
407+
```
408+
409+
> Note: 特别注意的是,CGO_LDFLAGS是可以有空格的,不能使用字符串,否则找不到库。
410+
332411
2021.01, Winlin

trunk/3rdparty/srs-bench/blackbox/hevc_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -935,8 +935,8 @@ func TestSlow_SrtPublish_HttpTsPlay_HEVC_Basic(t *testing.T) {
935935
}
936936

937937
// Note that HLS score is low, so we only check duration.
938-
if dv := m.Duration(); dv < duration / 2 {
939-
r5 = errors.Errorf("short duration=%v < %v, %v, %v", dv, duration / 2, m.String(), str)
938+
if dv := m.Duration(); dv < duration/2 {
939+
r5 = errors.Errorf("short duration=%v < %v, %v, %v", dv, duration/2, m.String(), str)
940940
}
941941

942942
if v := m.Video(); v == nil {

trunk/3rdparty/srs-bench/gb28181/gb28181.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in
@@ -57,7 +57,11 @@ func Parse(ctx context.Context) interface{} {
5757
fl.Usage = func() {
5858
fmt.Println(fmt.Sprintf("Usage: %v [Options]", os.Args[0]))
5959
fmt.Println(fmt.Sprintf("Options:"))
60-
fmt.Println(fmt.Sprintf(" -sfu The target SFU, srs or gb28181 or janus. Default: srs"))
60+
fmt.Println(fmt.Sprintf(" -sfu The target server that can be rtc, live, janus, or gb28181. Default: rtc"))
61+
fmt.Println(fmt.Sprintf(" rtc/srs: SRS WebRTC SFU server, for WebRTC/WHIP/WHEP."))
62+
fmt.Println(fmt.Sprintf(" live: SRS live streaming server, for RTMP/HTTP-FLV/HLS."))
63+
fmt.Println(fmt.Sprintf(" janus: Janus WebRTC SFU server, for janus private protocol."))
64+
fmt.Println(fmt.Sprintf(" gb28181: GB media server, for GB protocol."))
6165
fmt.Println(fmt.Sprintf("SIP:"))
6266
fmt.Println(fmt.Sprintf(" -user The SIP username, ID of device."))
6367
fmt.Println(fmt.Sprintf(" -random Append N number to user as random device ID, like 1320000001."))

trunk/3rdparty/srs-bench/gb28181/gb28181_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in

trunk/3rdparty/srs-bench/gb28181/gb_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in

trunk/3rdparty/srs-bench/gb28181/ingester.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in

trunk/3rdparty/srs-bench/gb28181/ps.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in

trunk/3rdparty/srs-bench/gb28181/sip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in

trunk/3rdparty/srs-bench/gb28181/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The MIT License (MIT)
22
//
3-
// Copyright (c) 2022 Winlin
3+
// # Copyright (c) 2022-2024 Winlin
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy of
66
// this software and associated documentation files (the "Software"), to deal in

trunk/3rdparty/srs-bench/go.mod

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.17
55
require (
66
github.com/ghettovoice/gosip v0.0.0-20220929080231-de8ba881be83
77
github.com/google/gopacket v1.1.19
8+
github.com/haivision/srtgo v0.0.0-20230627061225-a70d53fcd618
89
github.com/ossrs/go-oryx-lib v0.0.9
910
github.com/pion/ice/v2 v2.3.6
1011
github.com/pion/interceptor v0.1.17
@@ -28,6 +29,7 @@ require (
2829
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
2930
github.com/mattn/go-colorable v0.1.4 // indirect
3031
github.com/mattn/go-isatty v0.0.8 // indirect
32+
github.com/mattn/go-pointer v0.0.1 // indirect
3133
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
3234
github.com/pion/datachannel v1.5.5 // indirect
3335
github.com/pion/dtls/v2 v2.2.7 // indirect
@@ -40,12 +42,12 @@ require (
4042
github.com/pmezard/go-difflib v1.0.0 // indirect
4143
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
4244
github.com/sirupsen/logrus v1.4.2 // indirect
43-
github.com/stretchr/testify v1.8.4 // indirect
45+
github.com/stretchr/testify v1.9.0 // indirect
4446
github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5 // indirect
4547
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
46-
golang.org/x/crypto v0.9.0 // indirect
47-
golang.org/x/net v0.10.0 // indirect
48-
golang.org/x/sys v0.8.0 // indirect
49-
golang.org/x/term v0.8.0 // indirect
48+
golang.org/x/crypto v0.21.0 // indirect
49+
golang.org/x/net v0.21.0 // indirect
50+
golang.org/x/sys v0.18.0 // indirect
51+
golang.org/x/term v0.18.0 // indirect
5052
gopkg.in/yaml.v3 v3.0.1 // indirect
5153
)

0 commit comments

Comments
 (0)