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

SmartPtr: Support load test for source by srs-bench. v6.0.130 #4097

Merged
merged 11 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 20 additions & 5 deletions trunk/3rdparty/srs-bench/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
.PHONY: help default clean bench test
.PHONY: help default clean bench pcap test all

default: bench test

clean:
rm -rf ./objs

all: bench test pcap test

#########################################################################################################
# SRS benchmark tool for SRS, janus, GB28181.
./objs/.format.bench.txt: *.go janus/*.go ./objs/.format.srs.txt ./objs/.format.gb28181.txt
gofmt -w *.go janus
mkdir -p objs && echo "done" > ./objs/.format.bench.txt

bench: ./objs/srs_bench ./objs/pcap_simulator
bench: ./objs/srs_bench

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SRT_PREFIX := $(shell brew --prefix srt)
CGO_CFLAGS := -I$(SRT_PREFIX)/include
CGO_LDFLAGS := -L$(SRT_PREFIX)/lib -lsrt
else ifeq ($(UNAME_S),Linux)
CGO_CFLAGS := -I/usr/local/include
CGO_LDFLAGS := -L/usr/local/lib -lsrt -L/usr/local/ssl/lib -lcrypto -lstdc++ -lm -ldl
endif

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

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

pcap: ./objs/pcap_simulator

./objs/pcap_simulator: ./objs/.format.pcap.txt pcap/*.go Makefile
go build -mod=vendor -o ./objs/pcap_simulator ./pcap

Expand All @@ -59,9 +73,10 @@ test: ./objs/srs_test ./objs/srs_gb28181_test ./objs/srs_blackbox_test
#########################################################################################################
# Help menu.
help:
@echo "Usage: make [default|bench|test|clean]"
@echo "Usage: make [default|bench|pcap|test|clean]"
@echo " default The default entry for make is bench+test"
@echo " bench Make the bench to ./objs/srs_bench"
@echo " pcap Make the pcap simulator to ./objs/pcap_simulator"
@echo " test Make the test tool to ./objs/srs_test and ./objs/srs_gb28181_test ./objs/srs_blackbox_test"
@echo " clean Remove all tools at ./objs"

87 changes: 83 additions & 4 deletions trunk/3rdparty/srs-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ git clone -b feature/rtc https://github.com/ossrs/srs-bench.git &&
cd srs-bench && make
```

> Note: 依赖Go编译工具,建议使用 Go 1.17 及以上的版本。

编译会生成下面的工具:

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

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

## Player for Live
## Player for WHEP

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

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

## Publisher for Live or RTC
## Publisher for WHIP

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

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

> 注意:帧率是原始视频的帧率,由于264中没有这个信息所以需要传递。

## Multipel Player or Publisher for RTC
## Multiple WHIP or WHEP for RTC

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

Expand All @@ -84,7 +86,7 @@ ffmpeg -re -i doc/source.200kbps.768x320.flv -c copy -f flv -y rtmp://localhost/
> 备注:URL的变量格式参考Go的`fmt.Sprintf`,比如可以用`webrtc://localhost/live/livestream_%03d`。

<a name="dvr"></a>
## DVR for Benchmark
## DVR for RTC Benchmark

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

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

> Note: 可以传递更多参数,详细参考SRS支持的参数。

## Reconnecting Load Test

建立连接和断开重连的压测,可以测试SRS在多个Source时是否有内存泄露问题,参考 [#3667](https://github.com/ossrs/srs/discussions/3667#discussioncomment-8969107)

RTMP重连测试:

```bash
for ((i=0;;i++)); do
./objs/srs_bench -sfu=live -pr=rtmp://localhost/live${i}/stream -sn=1000 -cap=true;
sleep 10;
done
```

SRT重连测试:

```bash
for ((i=0;;i++)); do
./objs/srs_bench -sfu=live -pr='srt://127.0.0.1:10080?streamid=#!::'m=publish,r=live${i}/stream -sn=1000 -cap=true;
sleep 10;
done
```

WebRTC重连测试:

```bash
for ((i=0;;i++)); do
./objs/srs_bench -sfu=rtc -pr=webrtc://localhost/live${i}/livestream -sn=1000 -cap=true;
sleep 10;
done
```

## Regression Test

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

## Install LIBSRT

我们使用 [srtgo](https://github.com/Haivision/srtgo) 库测试SRT协议,需要安装libsrt库,
参考[macOS](https://github.com/Haivision/srt/blob/master/docs/build/build-macOS.md):

```bash
brew install srt
```

如果是Ubuntu,可以参考[Ubuntu](https://github.com/Haivision/srt/blob/master/docs/build/package-managers.md):

```bash
apt-get install -y libsrt
```

安装完libsrt后,直接编译srs-bench即可:

```bash
make
```

## Ubuntu Docker

如果使用Ubuntu编译,推荐使用 `ossrs/srs:ubuntu20` 作为镜像编译,已经编译了openssl和libsrt,启动容器:

```bash
docker run --rm -it -v $(pwd):/g -w /g ossrs/srs:ubuntu20 make
```

## GoLand

使用GoLand编译和调试时,需要设置libsrt的环境变量,首先可以使用brew获取路径:

```bash
brew --prefix srt
#/opt/homebrew/opt/srt
```

然后在GoLand中,编辑配置 `Edit Configurations`,添加环境变量:

```bash
CGO_CFLAGS=-I/opt/homebrew/opt/srt/include;CGO_LDFLAGS=-L/opt/homebrew/opt/srt/lib -lsrt
```

> Note: 特别注意的是,CGO_LDFLAGS是可以有空格的,不能使用字符串,否则找不到库。

2021.01, Winlin
4 changes: 2 additions & 2 deletions trunk/3rdparty/srs-bench/blackbox/hevc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,8 @@ func TestSlow_SrtPublish_HttpTsPlay_HEVC_Basic(t *testing.T) {
}

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

if v := m.Video(); v == nil {
Expand Down
8 changes: 6 additions & 2 deletions trunk/3rdparty/srs-bench/gb28181/gb28181.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -57,7 +57,11 @@ func Parse(ctx context.Context) interface{} {
fl.Usage = func() {
fmt.Println(fmt.Sprintf("Usage: %v [Options]", os.Args[0]))
fmt.Println(fmt.Sprintf("Options:"))
fmt.Println(fmt.Sprintf(" -sfu The target SFU, srs or gb28181 or janus. Default: srs"))
fmt.Println(fmt.Sprintf(" -sfu The target server that can be rtc, live, janus, or gb28181. Default: rtc"))
fmt.Println(fmt.Sprintf(" rtc/srs: SRS WebRTC SFU server, for WebRTC/WHIP/WHEP."))
fmt.Println(fmt.Sprintf(" live: SRS live streaming server, for RTMP/HTTP-FLV/HLS."))
fmt.Println(fmt.Sprintf(" janus: Janus WebRTC SFU server, for janus private protocol."))
fmt.Println(fmt.Sprintf(" gb28181: GB media server, for GB protocol."))
fmt.Println(fmt.Sprintf("SIP:"))
fmt.Println(fmt.Sprintf(" -user The SIP username, ID of device."))
fmt.Println(fmt.Sprintf(" -random Append N number to user as random device ID, like 1320000001."))
Expand Down
2 changes: 1 addition & 1 deletion trunk/3rdparty/srs-bench/gb28181/gb28181_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion trunk/3rdparty/srs-bench/gb28181/gb_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion trunk/3rdparty/srs-bench/gb28181/ingester.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion trunk/3rdparty/srs-bench/gb28181/ps.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion trunk/3rdparty/srs-bench/gb28181/sip.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
2 changes: 1 addition & 1 deletion trunk/3rdparty/srs-bench/gb28181/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The MIT License (MIT)
//
// Copyright (c) 2022 Winlin
// # Copyright (c) 2022-2024 Winlin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
Expand Down
12 changes: 7 additions & 5 deletions trunk/3rdparty/srs-bench/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.17
require (
github.com/ghettovoice/gosip v0.0.0-20220929080231-de8ba881be83
github.com/google/gopacket v1.1.19
github.com/haivision/srtgo v0.0.0-20230627061225-a70d53fcd618
github.com/ossrs/go-oryx-lib v0.0.9
github.com/pion/ice/v2 v2.3.6
github.com/pion/interceptor v0.1.17
Expand All @@ -28,6 +29,7 @@ require (
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/pion/datachannel v1.5.5 // indirect
github.com/pion/dtls/v2 v2.2.7 // indirect
Expand All @@ -40,12 +42,12 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5 // indirect
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading