Дать подготовке данных в генераторе нагрузки отдельный длинный таймаут: регистрация с Argon2id на реплике с половиной CPU не укладывается в таймаут измерений
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user