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

View File

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