From 05140a5cd528c386f87aceef88c43740b9879b06 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Fri, 18 Sep 2020 19:59:07 +0200 Subject: [PATCH] add stress tests --- Makefile | 9 +++++++-- stress/proxy/Dockerfile | 19 +++++++++++++++++++ stress/proxy/start.sh | 37 +++++++++++++++++++++++++++++++++++++ stress/publish/Dockerfile | 19 +++++++++++++++++++ stress/publish/start.sh | 23 +++++++++++++++++++++++ stress/read/Dockerfile | 19 +++++++++++++++++++ stress/read/start.sh | 30 ++++++++++++++++++++++++++++++ 7 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 stress/proxy/Dockerfile create mode 100644 stress/proxy/start.sh create mode 100644 stress/publish/Dockerfile create mode 100644 stress/publish/start.sh create mode 100644 stress/read/Dockerfile create mode 100644 stress/read/start.sh diff --git a/Makefile b/Makefile index 09f8a16a..6adb3af1 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ help: @echo " mod-tidy run go mod tidy" @echo " format format source files" @echo " test run available tests" + @echo " stress NAME=n run stress environment" @echo " run run app" @echo " release build release assets" @echo " dockerhub build and push docker hub images" @@ -52,6 +53,10 @@ test-nodocker: docker build -q test-images/$(IMG) -t rtsp-simple-server-test-$(IMG)$(NL)) go test -race -v . +stress: + docker build -q . -f stress/$(NAME)/Dockerfile -t temp + docker run --rm -it --network=host temp + define DOCKERFILE_RUN FROM amd64/$(BASE_IMAGE) RUN apk add --no-cache git ffmpeg @@ -68,14 +73,14 @@ define CONFIG_RUN #rtpPort: 8002 #rtcpPort: 8003 #metrics: yes -pprof: yes +#pprof: yes paths: all: # runOnPublish: ffmpeg -i rtsp://localhost:8554/$$RTSP_SERVER_PATH -c copy -f mpegts myfile_$$RTSP_SERVER_PATH.ts # readUser: test # readPass: tast - runOnDemand: ffmpeg -re -stream_loop -1 -i test-images/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:8554/$$RTSP_SERVER_PATH +# runOnDemand: ffmpeg -re -stream_loop -1 -i test-images/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:8554/$$RTSP_SERVER_PATH # proxied: # source: rtsp://192.168.2.198:8554/stream diff --git a/stress/proxy/Dockerfile b/stress/proxy/Dockerfile new file mode 100644 index 00000000..cfefcf97 --- /dev/null +++ b/stress/proxy/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.14-alpine3.12 + +RUN apk add --no-cache \ + ffmpeg + +RUN wget -O /video.mkv http://jell.yfish.us/media/jellyfish-10-mbps-hd-h264.mkv + +WORKDIR /s + +COPY go.mod go.sum ./ +RUN go mod download + +COPY *.go ./ +RUN go build -o /rtsp-simple-server . + +COPY stress/proxy/start.sh / +RUN chmod +x /start.sh + +ENTRYPOINT [ "/start.sh" ] diff --git a/stress/proxy/start.sh b/stress/proxy/start.sh new file mode 100644 index 00000000..f185cf0b --- /dev/null +++ b/stress/proxy/start.sh @@ -0,0 +1,37 @@ +#!/bin/sh -e + +PROXY_COUNT=10 +PROXY_PROTOCOL=tcp + +##################################################### +# source + +CONF="" +CONF="${CONF}rtspPort: 8555\n" +CONF="${CONF}rtpPort: 8002\n" +CONF="${CONF}rtcpPort: 8003\n" +echo -e "$CONF" > /source.conf + +/rtsp-simple-server /source.conf & + +sleep 1 + +ffmpeg -hide_banner -loglevel error \ +-re -stream_loop -1 -i /video.mkv -c copy -f rtsp rtsp://localhost:8555/source & + +sleep 1 + +##################################################### +# proxy + +CONF="" +CONF="${CONF}pprof: yes\n" +CONF="${CONF}paths:\n" +for i in $(seq 1 $PROXY_COUNT); do + CONF="${CONF} proxy$i:\n" + CONF="${CONF} source: rtsp://localhost:8555/source\n" + CONF="${CONF} sourceProtocol: $PROXY_PROTOCOL\n" +done +echo -e "$CONF" > /proxy.conf + +/rtsp-simple-server /proxy.conf diff --git a/stress/publish/Dockerfile b/stress/publish/Dockerfile new file mode 100644 index 00000000..17871af4 --- /dev/null +++ b/stress/publish/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.14-alpine3.12 + +RUN apk add --no-cache \ + ffmpeg + +RUN wget -O /video.mkv http://jell.yfish.us/media/jellyfish-10-mbps-hd-h264.mkv + +WORKDIR /s + +COPY go.mod go.sum ./ +RUN go mod download + +COPY *.go ./ +RUN go build -o /rtsp-simple-server . + +COPY stress/publish/start.sh / +RUN chmod +x /start.sh + +ENTRYPOINT [ "/start.sh" ] diff --git a/stress/publish/start.sh b/stress/publish/start.sh new file mode 100644 index 00000000..c4179ebc --- /dev/null +++ b/stress/publish/start.sh @@ -0,0 +1,23 @@ +#!/bin/sh -e + +PUBLISHER_COUNT=10 +PUBLISHER_PROTOCOL=tcp + +##################################################### +# publishers + +CONF="" +CONF="${CONF}pprof: yes\n" +echo -e "$CONF" > /source.conf + +/rtsp-simple-server /source.conf & + +sleep 1 + +for i in $(seq 1 $PUBLISHER_COUNT); do + ffmpeg -hide_banner -loglevel error \ + -re -stream_loop -1 -i /video.mkv -c copy -f rtsp \ + -rtsp_transport $PUBLISHER_PROTOCOL rtsp://localhost:8554/source$i & +done + +wait diff --git a/stress/read/Dockerfile b/stress/read/Dockerfile new file mode 100644 index 00000000..c5dbca91 --- /dev/null +++ b/stress/read/Dockerfile @@ -0,0 +1,19 @@ +FROM golang:1.14-alpine3.12 + +RUN apk add --no-cache \ + ffmpeg + +RUN wget -O /video.mkv http://jell.yfish.us/media/jellyfish-10-mbps-hd-h264.mkv + +WORKDIR /s + +COPY go.mod go.sum ./ +RUN go mod download + +COPY *.go ./ +RUN go build -o /rtsp-simple-server . + +COPY stress/read/start.sh / +RUN chmod +x /start.sh + +ENTRYPOINT [ "/start.sh" ] diff --git a/stress/read/start.sh b/stress/read/start.sh new file mode 100644 index 00000000..76dae56b --- /dev/null +++ b/stress/read/start.sh @@ -0,0 +1,30 @@ +#!/bin/sh -e + +READER_COUNT=10 +READER_PROTOCOL=tcp + +##################################################### +# source + +CONF="" +CONF="${CONF}pprof: yes\n" +echo -e "$CONF" > /source.conf + +/rtsp-simple-server /source.conf & + +sleep 1 + +ffmpeg -re -stream_loop -1 -i /video.mkv -c copy -f rtsp rtsp://localhost:8554/source & + +sleep 1 + +##################################################### +# readers + +for i in $(seq 1 $READER_COUNT); do + ffmpeg -hide_banner -loglevel error \ + -rtsp_transport $READER_PROTOCOL \ + -i rtsp://localhost:8554/source -c copy -f mpegts -y /dev/null & +done + +wait