feat(bench): add load test flags, bench matrix and plot scripts

This commit is contained in:
kk10
2026-10-20 13:18:07 +03:00
parent 3f639bd7e6
commit 9cfe15ef1a
5 changed files with 234 additions and 2 deletions
+25
View File
@@ -4,8 +4,10 @@ package studenttests_test
import (
"flag"
"fmt"
"io"
"net/http"
"os"
"sort"
"sync"
"sync/atomic"
@@ -17,6 +19,8 @@ var (
workers = flag.Int("workers", 20, "number of concurrent workers")
duration = flag.Duration("duration", 5*time.Second, "test duration")
rate = flag.Int("rate", 20, "maximum requests per second per worker")
csvPath = flag.String("csv", "", "append result row to this CSV file")
label = flag.String("label", "", "configuration label for CSV row")
)
func TestLoad(t *testing.T) {
@@ -129,6 +133,27 @@ func TestLoad(t *testing.T) {
t.Logf("successful latency p95: %s", percentile(latencies, 0.95))
t.Logf("successful latency p99: %s", percentile(latencies, 0.99))
}
if *csvPath != "" {
var p50, p95, p99 time.Duration
if len(latencies) > 0 {
p50 = percentile(latencies, 0.50)
p95 = percentile(latencies, 0.95)
p99 = percentile(latencies, 0.99)
}
f, err := os.OpenFile(*csvPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
t.Fatalf("open csv: %v", err)
}
defer f.Close()
fmt.Fprintf(f, "%s,%d,%d,%d,%d,%d,%d,%.2f,%.1f,%.1f,%.1f\n",
*label, *workers, *rate, *workers**rate,
successful, total-successful-requestErrors, requestErrors,
float64(successful)/elapsed.Seconds(),
float64(p50.Microseconds())/1000,
float64(p95.Microseconds())/1000,
float64(p99.Microseconds())/1000)
}
}
func percentile(values []time.Duration, p float64) time.Duration {