From b4776ea4e0dfab9e9b67e14f29088dab96052b90 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 12 Apr 2025 17:18:06 +0200 Subject: [PATCH] feat(stdiscosrv): configurable desired not-found rate --- cmd/stdiscosrv/apisrv.go | 6 +++--- cmd/stdiscosrv/apisrv_test.go | 2 +- cmd/stdiscosrv/main.go | 15 ++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/stdiscosrv/apisrv.go b/cmd/stdiscosrv/apisrv.go index e714937fa..ec0c3520e 100644 --- a/cmd/stdiscosrv/apisrv.go +++ b/cmd/stdiscosrv/apisrv.go @@ -66,7 +66,7 @@ type contextKey int const idKey contextKey = iota -func newAPISrv(addr string, cert tls.Certificate, db database, repl replicator, useHTTP, compression bool) *apiSrv { +func newAPISrv(addr string, cert tls.Certificate, db database, repl replicator, useHTTP, compression bool, desiredNotFoundRate float64) *apiSrv { return &apiSrv{ addr: addr, cert: cert, @@ -77,13 +77,13 @@ func newAPISrv(addr string, cert tls.Certificate, db database, repl replicator, seenTracker: &retryAfterTracker{ name: "seenTracker", bucketStarts: time.Now(), - desiredRate: 250, + desiredRate: desiredNotFoundRate / 2, currentDelay: notFoundRetryUnknownMinSeconds, }, notSeenTracker: &retryAfterTracker{ name: "notSeenTracker", bucketStarts: time.Now(), - desiredRate: 250, + desiredRate: desiredNotFoundRate / 2, currentDelay: notFoundRetryUnknownMaxSeconds / 2, }, } diff --git a/cmd/stdiscosrv/apisrv_test.go b/cmd/stdiscosrv/apisrv_test.go index 272c0ca12..07dfa2f17 100644 --- a/cmd/stdiscosrv/apisrv_test.go +++ b/cmd/stdiscosrv/apisrv_test.go @@ -111,7 +111,7 @@ func BenchmarkAPIRequests(b *testing.B) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() go db.Serve(ctx) - api := newAPISrv("127.0.0.1:0", tls.Certificate{}, db, nil, true, true) + api := newAPISrv("127.0.0.1:0", tls.Certificate{}, db, nil, true, true, 1000) srv := httptest.NewServer(http.HandlerFunc(api.handler)) kf := b.TempDir() + "/cert" diff --git a/cmd/stdiscosrv/main.go b/cmd/stdiscosrv/main.go index 027c4978d..a870651d1 100644 --- a/cmd/stdiscosrv/main.go +++ b/cmd/stdiscosrv/main.go @@ -60,12 +60,13 @@ const ( var debug = false type CLI struct { - Cert string `group:"Listen" help:"Certificate file" default:"./cert.pem" env:"DISCOVERY_CERT_FILE"` - Key string `group:"Listen" help:"Key file" default:"./key.pem" env:"DISCOVERY_KEY_FILE"` - HTTP bool `group:"Listen" help:"Listen on HTTP (behind an HTTPS proxy)" env:"DISCOVERY_HTTP"` - Compression bool `group:"Listen" help:"Enable GZIP compression of responses" env:"DISCOVERY_COMPRESSION"` - Listen string `group:"Listen" help:"Listen address" default:":8443" env:"DISCOVERY_LISTEN"` - MetricsListen string `group:"Listen" help:"Metrics listen address" env:"DISCOVERY_METRICS_LISTEN"` + Cert string `group:"Listen" help:"Certificate file" default:"./cert.pem" env:"DISCOVERY_CERT_FILE"` + Key string `group:"Listen" help:"Key file" default:"./key.pem" env:"DISCOVERY_KEY_FILE"` + HTTP bool `group:"Listen" help:"Listen on HTTP (behind an HTTPS proxy)" env:"DISCOVERY_HTTP"` + Compression bool `group:"Listen" help:"Enable GZIP compression of responses" env:"DISCOVERY_COMPRESSION"` + Listen string `group:"Listen" help:"Listen address" default:":8443" env:"DISCOVERY_LISTEN"` + MetricsListen string `group:"Listen" help:"Metrics listen address" env:"DISCOVERY_METRICS_LISTEN"` + DesiredNotFoundRate float64 `group:"Listen" help:"Desired maximum rate of not-found replies (/s)" default:"1000"` DBDir string `group:"Database" help:"Database directory" default:"." env:"DISCOVERY_DB_DIR"` DBFlushInterval time.Duration `group:"Database" help:"Interval between database flushes" default:"5m" env:"DISCOVERY_DB_FLUSH_INTERVAL"` @@ -149,7 +150,7 @@ func main() { } // Start the main API server. - qs := newAPISrv(cli.Listen, cert, db, repl, cli.HTTP, cli.Compression) + qs := newAPISrv(cli.Listen, cert, db, repl, cli.HTTP, cli.Compression, cli.DesiredNotFoundRate) main.Add(qs) // If we have a metrics port configured, start a metrics handler.