Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ profile.cov

# goreleaser output
dist/

# Written by bench/run.sh before each condition; the mount target, not source.
bench/strategy.dna
8 changes: 8 additions & 0 deletions .mise/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ run = "golangci-lint run ./..."
description = "go vet over the module"
run = "make vet"

[tasks.bench]
description = "engine microbenchmarks (per-packet cost, no kernel in the loop)"
run = "make bench"

[tasks."bench:e2e"]
description = "data-plane benchmark over docker: throughput + sidecar CPU per GiB"
run = "make bench-e2e"

[tasks.e2e]
description = "full docker-networking e2e (needs docker + a netfilter-capable kernel)"
run = "make e2e"
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT)

.PHONY: build test test-race vet lint e2e docker package clean
.PHONY: build test test-race bench bench-e2e vet lint e2e docker package clean

build:
CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/geneva-server ./cmd/geneva-server
Expand All @@ -23,6 +23,17 @@ vet:
lint:
golangci-lint run ./...

# Per-packet cost of the engine, with no kernel in the loop. The fastest signal
# when changing the hot path; run bench-e2e for the number that includes NFQUEUE.
bench:
go test ./internal/engine/ ./internal/nfqueue/ -run '^$$' -bench . -benchmem

# Full data-plane benchmark over docker networking: throughput and sidecar CPU
# per GiB across every sidecar state. Args: GiB per condition, concurrent
# streams.
bench-e2e:
./bench/run.sh $(GIB) $(STREAMS)

# Full e2e over docker networking (requires docker + a netfilter-capable kernel).
e2e:
./e2e/run.sh
Expand Down
16 changes: 16 additions & 0 deletions bench/Dockerfile.bulk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Benchmark-only image: the bulk load generator plus the tooling the runner uses
# to drive the control API and read the sidecar's counters.
FROM golang:1.25-bookworm AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -o /out/bulk ./bench/bulk

FROM debian:bookworm-slim
RUN set -ex \
&& apt-get update \
&& apt-get install -y --no-install-recommends curl jq ethtool ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /out/bulk /usr/local/bin/bulk
ENTRYPOINT ["/usr/local/bin/bulk"]
136 changes: 136 additions & 0 deletions bench/bulk/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// Command bulk is the load generator for the sidecar benchmark. It is both the
// server and the client so that a single image covers both ends, and it streams
// from a reused buffer rather than materializing the payload: the benchmark
// moves gigabytes, and a payload held in memory would measure the allocator.
//
// It deliberately speaks plain HTTP. The sidecar only ever manipulates outer
// IPv4/TCP headers, so wrapping the stream in TLS would add proxy-side crypto
// cost to every number without changing a single packet the sidecar sees.
package main

import (
"crypto/rand"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"sync"
"time"
)

const chunkSize = 256 << 10

func main() {
serve := flag.String("serve", "", "serve bulk data on this address (e.g. :8080)")
get := flag.String("get", "", "fetch bulk data from this base URL (e.g. http://server:8080)")
bytes := flag.Int64("bytes", 2<<30, "bytes to transfer per stream")
streams := flag.Int("streams", 1, "concurrent streams")
flag.Parse()

switch {
case *serve != "":
runServer(*serve)
case *get != "":
if err := runClient(*get, *bytes, *streams); err != nil {
// Exit non-zero rather than printing a throughput figure: a
// half-finished transfer that reports a number is how a broken
// condition gets recorded as a benchmark result.
log.Fatal(err)
}
default:
log.Fatal("one of -serve or -get is required")
}
}

func runServer(addr string) {
// Random rather than zeros: a NIC or a virtual link that compresses or
// dedupes would otherwise flatter the benchmark.
chunk := make([]byte, chunkSize)
if _, err := rand.Read(chunk); err != nil {
log.Fatal(err)
}

mux := http.NewServeMux()
mux.HandleFunc("/bulk", func(w http.ResponseWriter, r *http.Request) {
n, err := strconv.ParseInt(r.URL.Query().Get("bytes"), 10, 64)
if err != nil || n < 0 {
http.Error(w, "bad bytes", http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", strconv.FormatInt(n, 10))
for n > 0 {
c := int64(len(chunk))
if n < c {
c = n
}
if _, err := w.Write(chunk[:c]); err != nil {
return
}
n -= c
}
})
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("ok"))
})

log.Printf("bulk server listening on %s", addr)
srv := &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second}
log.Fatal(srv.ListenAndServe())
}

// runClient reports MB/s on stdout as a bare number, so the runner can read it
// without parsing prose. Any stream that fails, returns a non-200, or comes up
// short is an error: the number would be meaningless and the runner cannot tell
// a slow condition from a broken one.
func runClient(base string, n int64, streams int) error {
client := &http.Client{Timeout: 30 * time.Minute}
url := fmt.Sprintf("%s/bulk?bytes=%d", base, n)

var wg sync.WaitGroup
got := make([]int64, streams)
errs := make([]error, streams)
start := time.Now()
for i := range streams {
wg.Add(1)
go func(i int) {
defer wg.Done()
resp, err := client.Get(url)
if err != nil {
errs[i] = fmt.Errorf("stream %d: %w", i, err)
return
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK {
errs[i] = fmt.Errorf("stream %d: HTTP %d", i, resp.StatusCode)
return
}
c, err := io.Copy(io.Discard, resp.Body)
got[i] = c
if err != nil {
errs[i] = fmt.Errorf("stream %d: after %d bytes: %w", i, c, err)
}
}(i)
}
wg.Wait()
elapsed := time.Since(start)

for _, err := range errs {
if err != nil {
return err
}
}
var total int64
for _, c := range got {
total += c
}
if want := n * int64(streams); total != want {
return fmt.Errorf("short transfer: got %d of %d bytes", total, want)
}
mbps := float64(total) / (1 << 20) / elapsed.Seconds()
_, _ = fmt.Fprintf(os.Stdout, "%.2f\n", mbps)
return nil
}
64 changes: 64 additions & 0 deletions bench/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Benchmark topology. Mirrors e2e/docker-compose.yml, with the echo server
# replaced by a streaming bulk server and the sidecar's arguments driven from
# the environment so the runner can sweep modes without editing this file.
#
# server — the "proxy": bulk data on :8080, and owner of the network namespace
# sidecar — geneva-server sharing the server's netns, steering :8080
# client — pulls bulk data across the bridge; the load generator
# probe — on-demand container in the server's netns for nft/ethtool state
name: geneva-bench

services:
server:
build:
context: ..
dockerfile: bench/Dockerfile.bulk
image: geneva-bench/bulk:latest
command: ["-serve", ":8080"]
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
interval: "1s"
timeout: "2s"
retries: 30

sidecar:
build:
context: ..
dockerfile: Dockerfile
image: geneva-bench/sidecar:latest
network_mode: "service:server"
cap_add:
- NET_ADMIN
- NET_RAW
depends_on:
server:
condition: service_healthy
volumes:
- ./strategy.dna:/strategy.dna:ro
command:
- "run"
- "--mode=${GENEVA_MODE:-eval}"
- "--market=RU"
- "--port=8080"
- "--iface=eth0"
- "--control-addr=0.0.0.0:8092"
# Always a file, never a flag toggle: the runner rewrites strategy.dna
# between conditions, and an empty file is exactly the pass-through case.
- "--strategy-file=/strategy.dna"
# Debug-only, and only ever in this harness: the profile is what tells us
# whether a cost is in the engine or in the plumbing around it.
- "--pprof-addr=0.0.0.0:6060"

client:
image: geneva-bench/bulk:latest
depends_on:
server:
condition: service_healthy
profiles: ["tools"]
entrypoint: ["sleep", "infinity"]

probe:
image: geneva-bench/sidecar:latest
network_mode: "service:server"
profiles: ["tools"]
entrypoint: ["sleep", "infinity"]
Loading