Skip to content

Commit d4a32fb

Browse files
committed
feat: add the main program for perftest
1 parent 4667eb8 commit d4a32fb

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

cmd/perftest/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM alpine:latest
2+
LABEL maintainer="zhufuyi <g.zhufuyi@gmail.com>"
3+
4+
# set the time zone to Shanghai
5+
#RUN apk add tzdata \
6+
# && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
7+
# && echo "Asia/Shanghai" > /etc/timezone \
8+
# && apk del tzdata
9+
10+
COPY perftest /app/perftest
11+
RUN chmod +x /app/perftest
12+
13+
# 8888 for collector, 6601 for agent
14+
EXPOSE 8888 6601
15+
16+
WORKDIR /app
17+
18+
ENTRYPOINT ["./perftest"]

cmd/perftest/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Performance Testing Tool `perftest`
2+
3+
### Documentation
4+
5+
For the usage guide of `perftest`, please refer to [**perftest documentation**](https://go-sponge.com/component/monitor/perftest.html)
6+
7+
<br>
8+
9+
### Build Docker Image
10+
11+
```shell
12+
# Build perftest image
13+
bash build-perftest-image.sh v1.0.0
14+
15+
# push perftest image to Docker Hub
16+
#docker push zhufuyi/perftest:v1.0.0
17+
#docker push zhufuyi/perftest:latest
18+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
TAG=$1
4+
if [ -z "$TAG" ];then
5+
echo "image tag cannot be empty, example: ./build-perftest-image.sh v1.0.0"
6+
exit 1
7+
fi
8+
9+
function rmFile() {
10+
sFile=$1
11+
if [ -e "${sFile}" ]; then
12+
rm -rf "${sFile}"
13+
fi
14+
}
15+
16+
function checkResult() {
17+
result=$1
18+
if [ ${result} -ne 0 ]; then
19+
exit ${result}
20+
fi
21+
}
22+
23+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "all=-s -w"
24+
checkResult $?
25+
26+
# compressing binary file
27+
if command -v upx >/dev/null 2>&1; then
28+
upx -9 perftest
29+
else
30+
echo "upx not found, skipping compression"
31+
fi
32+
33+
echo "docker build -t zhufuyi/perftest:${TAG} ."
34+
docker build -t zhufuyi/perftest:${TAG} .
35+
echo "docker tag zhufuyi/perftest:${TAG} zhufuyi/perftest:latest"
36+
docker tag zhufuyi/perftest:${TAG} zhufuyi/perftest:latest
37+
checkResult $?
38+
39+
rmFile perftest
40+
41+
# delete none image
42+
noneImages=$(docker images --filter "dangling=true" -q)
43+
if [ -n "$noneImages" ]; then
44+
docker rmi $noneImages > /dev/null
45+
fi
46+
47+
# push image to docker hub
48+
#docker push zhufuyi/perftest:${TAG}
49+
#docker push zhufuyi/perftest:latest

cmd/perftest/main.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/go-dev-frame/sponge/cmd/sponge/commands/perftest/common"
9+
"github.com/go-dev-frame/sponge/cmd/sponge/commands/perftest/http"
10+
"github.com/go-dev-frame/sponge/cmd/sponge/commands/perftest/websocket"
11+
)
12+
13+
func main() {
14+
cmd := perftestCommand()
15+
if err := cmd.Execute(); err != nil {
16+
cmd.PrintErrln("Error:", err)
17+
os.Exit(1)
18+
}
19+
}
20+
21+
func perftestCommand() *cobra.Command {
22+
common.SetCommandPrefix("perftest")
23+
cmd := &cobra.Command{
24+
Use: "perftest",
25+
Short: "Performance testing for HTTP/1.1, HTTP/2, HTTP/3, and websocket",
26+
Long: `Perftest is a high-performance testing tool that supports HTTP/1.1, HTTP/2, HTTP/3, and WebSocket protocols.
27+
It provides real-time metrics reporting to custom HTTP endpoints or Prometheus, and supports two modes:
28+
standalone testing and distributed cluster testing.`,
29+
SilenceErrors: true,
30+
SilenceUsage: true,
31+
}
32+
33+
cmd.AddCommand(
34+
http.PerfTestHTTPCMD(),
35+
http.PerfTestHTTP2CMD(),
36+
http.PerfTestHTTP3CMD(),
37+
websocket.PerfTestWebsocketCMD(),
38+
39+
http.PerfTestCollectorCMD(),
40+
http.PerfTestAgentCMD(),
41+
)
42+
43+
return cmd
44+
}

0 commit comments

Comments
 (0)