refactor(benchmark): replace whoami service with bench server

- Updated dev.compose.yml to define a new bench service that serves 4096 bytes of random data.
- Modified configurations for Traefik, Caddy, and Nginx to route traffic to the new bench service.
- Added Dockerfile and Go application for the bench server, including necessary Go modules.
- Updated benchmark script to target the new bench service endpoint.
This commit is contained in:
yusing
2026-01-03 12:40:10 +08:00
parent 880e11c414
commit 5de064aa47
6 changed files with 80 additions and 23 deletions

View File

@@ -0,0 +1,18 @@
FROM golang:1.25.5-alpine AS builder
HEALTHCHECK NONE
WORKDIR /src
COPY go.mod go.sum ./
COPY main.go ./
RUN go build -o bench_server main.go
FROM scratch
COPY --from=builder /src/bench_server /app/run
USER 1001:1001
CMD ["/app/run"]

3
cmd/bench_server/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/yusing/godoxy/cmd/bench_server
go 1.25.5

0
cmd/bench_server/go.sum Normal file
View File

34
cmd/bench_server/main.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
"log"
"net/http"
"math/rand/v2"
)
var printables = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var random = make([]byte, 4096)
func init() {
for i := range random {
random[i] = printables[rand.IntN(len(printables))]
}
}
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(random)
})
server := &http.Server{
Addr: ":80",
Handler: handler,
}
log.Println("Bench server listening on :80")
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("ListenAndServe: %v", err)
}
}

View File

@@ -95,10 +95,12 @@ services:
labels:
proxy.#1.scheme: h2c
proxy.#1.port: 80
whoami:
bench: # returns 4096 bytes of random data
<<: *benchmark
image: traefik/whoami:latest
container_name: whoami
build:
context: cmd/bench_server
dockerfile: Dockerfile
container_name: bench
godoxy:
<<: *benchmark
build: .
@@ -156,22 +158,22 @@ configs:
- providers.yml
godoxy_provider:
content: |
whoami.domain.com:
host: whoami
bench.domain.com:
host: bench
traefik_config:
content: |
http:
routers:
whoami:
rule: "Host(`whoami.domain.com`)"
bench:
rule: "Host(`bench.domain.com`)"
entryPoints:
- web
service: whoami
service: bench
services:
whoami:
bench:
loadBalancer:
servers:
- url: "http://whoami:80"
- url: "http://bench:80"
caddy_config:
content: |
{
@@ -184,8 +186,8 @@ configs:
}
}
http://whoami.domain.com {
reverse_proxy whoami:80
http://bench.domain.com {
reverse_proxy bench:80
}
nginx_config:
content: |
@@ -213,7 +215,7 @@ configs:
keepalive_requests 10000;
upstream backend {
server whoami:80;
server bench:80;
keepalive 128;
}
@@ -227,7 +229,7 @@ configs:
server {
listen 80;
server_name whoami.domain.com;
server_name bench.domain.com;
http2 on;
location / {

View File

@@ -5,7 +5,7 @@
set -e
# Configuration
HOST="whoami.domain.com"
HOST="bench.domain.com"
DURATION="${DURATION:-10s}"
THREADS="${THREADS:-4}"
CONNECTIONS="${CONNECTIONS:-100}"
@@ -54,10 +54,10 @@ echo ""
# Define services to test
declare -A services=(
["GoDoxy"]="http://127.0.0.1:8080/bench"
["Traefik"]="http://127.0.0.1:8081/bench"
["Caddy"]="http://127.0.0.1:8082/bench"
["Nginx"]="http://127.0.0.1:8083/bench"
["GoDoxy"]="http://127.0.0.1:8080"
["Traefik"]="http://127.0.0.1:8081"
["Caddy"]="http://127.0.0.1:8082"
["Nginx"]="http://127.0.0.1:8083"
)
# Array to store connection errors
@@ -81,13 +81,13 @@ test_connection() {
local status2=$(echo "$res2" | tail -n 1)
local failed=false
if [ "$status1" != "200" ] || [ "$body1" != "1" ]; then
red "$name failed HTTP/1.1 connection test (Status: $status1, Body: $body1)"
if [ "$status1" != "200" ] || [ ${#body1} -ne 4096 ]; then
red "$name failed HTTP/1.1 connection test (Status: $status1, Body length: ${#body1})"
failed=true
fi
if [ "$status2" != "200" ] || [ "$body2" != "1" ]; then
red "$name failed HTTP/2 connection test (Status: $status2, Body: $body2)"
if [ "$status2" != "200" ] || [ ${#body2} -ne 4096 ]; then
red "$name failed HTTP/2 connection test (Status: $status2, Body length: ${#body2})"
failed=true
fi