diff --git a/cmd/gosky/main.go b/cmd/gosky/main.go index d2e231241..fd572282b 100644 --- a/cmd/gosky/main.go +++ b/cmd/gosky/main.go @@ -25,6 +25,7 @@ import ( "github.com/bluesky-social/indigo/util" "github.com/bluesky-social/indigo/util/cliutil" "github.com/bluesky-social/indigo/xrpc" + "golang.org/x/time/rate" "github.com/gorilla/websocket" lru "github.com/hashicorp/golang-lru" @@ -143,6 +144,10 @@ var readRepoStreamCmd = &cli.Command{ &cli.BoolFlag{ Name: "resolve-handles", }, + &cli.Float64Flag{ + Name: "max-throughput", + Usage: "limit event consumption to a given # of req/sec (debug utility)", + }, }, ArgsUsage: `[ [cursor]]`, Action: func(cctx *cli.Context) error { @@ -203,9 +208,17 @@ var readRepoStreamCmd = &cli.Command{ return h, nil } + var limiter *rate.Limiter + if cctx.Float64("max-throughput") > 0 { + limiter = rate.NewLimiter(rate.Limit(cctx.Float64("max-throughput")), 1) + } rsc := &events.RepoStreamCallbacks{ RepoCommit: func(evt *comatproto.SyncSubscribeRepos_Commit) error { + if limiter != nil { + limiter.Wait(ctx) + } + if jsonfmt { b, err := json.Marshal(evt) if err != nil {