From 25f9564fd78ea07df25af776b00e9678030bfc58 Mon Sep 17 00:00:00 2001 From: kudesn1k Date: Wed, 4 Nov 2026 13:36:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B0=D1=82=D1=8C=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BA=D0=B5=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B2=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=B5=20=D0=BD=D0=B0=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B7=D0=BA=D0=B8=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=B4=D0=BB=D0=B8=D0=BD=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=82=D0=B0=D0=B9=D0=BC=D0=B0=D1=83=D1=82:=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81?= =?UTF-8?q?=20Argon2id=20=D0=BD=D0=B0=20=D1=80=D0=B5=D0=BF=D0=BB=D0=B8?= =?UTF-8?q?=D0=BA=D0=B5=20=D1=81=20=D0=BF=D0=BE=D0=BB=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20CPU=20=D0=BD=D0=B5=20=D1=83=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B2?= =?UTF-8?q?=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B0=D1=83=D1=82=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/loadgen/main.go | 4 ++-- tools/loadgen/main_test.go | 33 ++++++++++++++++++++++++++++++++- tools/loadgen/seed.go | 5 +++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/tools/loadgen/main.go b/tools/loadgen/main.go index f081d981..2873bfee 100644 --- a/tools/loadgen/main.go +++ b/tools/loadgen/main.go @@ -158,7 +158,7 @@ type benchReport struct { func runBench(ctx context.Context, cfg config) error { c := newClient(cfg.BaseURL, cfg.timeout) rng := mrand.New(mrand.NewPCG(cfg.Seed, 0x6c6f6164)) - ds, err := seed(ctx, c, rng, cfg.Users, cfg.Chats, cfg.SeedMessages) + ds, err := seed(ctx, newClient(cfg.BaseURL, seedTimeout), rng, cfg.Users, cfg.Chats, cfg.SeedMessages) if err != nil { return err } @@ -245,7 +245,7 @@ const retryGrace = 10 * time.Second func runTimeline(ctx context.Context, cfg config) error { c := newClient(cfg.BaseURL, cfg.timeout) rng := mrand.New(mrand.NewPCG(cfg.Seed, 0x74696d65)) - ds, err := seed(ctx, c, rng, 2, 1, 0) + ds, err := seed(ctx, newClient(cfg.BaseURL, seedTimeout), rng, 2, 1, 0) if err != nil { return err } diff --git a/tools/loadgen/main_test.go b/tools/loadgen/main_test.go index 78dba77c..4f6c8c75 100644 --- a/tools/loadgen/main_test.go +++ b/tools/loadgen/main_test.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log/slog" + "net/http" "net/http/httptest" "os" "path/filepath" @@ -41,6 +42,10 @@ func TestMain(m *testing.M) { } func liveServer(t *testing.T) string { + return serve(t, nil) +} + +func serve(t *testing.T, wrap func(http.Handler) http.Handler) string { t.Helper() a := app.New(app.Deps{ Log: slog.New(slog.NewTextHandler(io.Discard, nil)), @@ -50,11 +55,37 @@ func liveServer(t *testing.T) string { MaxBodyBytes: 64 * 1024, InstanceID: "loadgen-test", }) - srv := httptest.NewServer(a.Engine) + var h http.Handler = a.Engine + if wrap != nil { + h = wrap(h) + } + srv := httptest.NewServer(h) t.Cleanup(srv.Close) return srv.URL } +// Registration hashes a password with Argon2id, which is slow on a small +// replica; the setup is not measured, so it must not fail on the short +// timeout of the measured requests. +func TestSlowSetupDoesNotFailTheRun(t *testing.T) { + slowAccounts := func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost && (r.URL.Path == "/api/v1/users" || r.URL.Path == "/api/v1/auth/sessions") { + time.Sleep(300 * time.Millisecond) + } + next.ServeHTTP(w, r) + }) + } + cfg, err := parse("bench", []string{"-base-url", serve(t, slowAccounts), "-users", "2", "-chats", "1", "-seed-messages", "1", + "-rates", "10", "-step", "1s", "-warmup", "0s", "-timeout", "100ms", "-out", t.TempDir()}) + if err != nil { + t.Fatal(err) + } + if err := runBench(context.Background(), cfg); err != nil { + t.Fatalf("a setup slower than -timeout failed the run: %v", err) + } +} + func TestBenchAgainstLiveServer(t *testing.T) { out := t.TempDir() cfg, err := parse("bench", []string{"-base-url", liveServer(t), "-users", "4", "-chats", "2", "-seed-messages", "3", diff --git a/tools/loadgen/seed.go b/tools/loadgen/seed.go index 748b0c18..61624236 100644 --- a/tools/loadgen/seed.go +++ b/tools/loadgen/seed.go @@ -7,6 +7,7 @@ import ( "fmt" mrand "math/rand/v2" "sync" + "time" "github.com/google/uuid" ) @@ -14,6 +15,10 @@ import ( // seedPassword is shared by the synthetic users of one run. const seedPassword = "loadgen-synthetic-password" +// seedTimeout bounds one setup request. The setup is not measured, and +// registration hashes a password with Argon2id, slow on a small replica. +const seedTimeout = 30 * time.Second + // seedWorkers bounds the parallel registrations: each one hashes a password // with Argon2id, and the setup must not be what the study measures. const seedWorkers = 8