From f3dcc26bd9cdf82985c8dfea02a4547dc466e6ec Mon Sep 17 00:00:00 2001 From: Andrew Gillis <11790789+gammazero@users.noreply.github.com> Date: Tue, 3 Dec 2024 08:49:07 -1000 Subject: [PATCH] feat: add flags to configure bitswap tuning params (#203) * feat: allow configuration of bitswap/routing tuning params. New CLI flags: - `routing-max-requests` - Maximum number of concurrent find requests - `routing-max-providers` - Maximum number of providers to return for each find request - `routing-max-timeout` - Maximum time for to find the maximum number of providers Corresponding environ vars: `ROUTING_MAX_REQUESTS` `ROUTING_MAX_PROVIDERS` `ROUTING_MAX_TIMEOUT` --- CHANGELOG.md | 4 ++++ main.go | 23 +++++++++++++++++++++++ setup.go | 5 +++++ setup_bitswap.go | 6 +++++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02562fe..b202536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ The following emojis are used to highlight certain changes: ### Added - Added endpoints to show and purge connected peers [#194](https://github.com/ipfs/rainbow/pull/194) +- Added flags to configure bitswap/routing tuning params: + - `routing-max-requests` + - `routing-max-providers` + - `routing-max-timeout` ### Changed diff --git a/main.go b/main.go index d373dfc..d5f3c85 100644 --- a/main.go +++ b/main.go @@ -381,6 +381,24 @@ Generate an identity seed and launch a gateway: EnvVars: []string{"PEBBLE_WAL_MIN_SYNC_INTERVAL"}, Usage: "Sets the minimum duration between syncs of the WAL", }, + &cli.IntFlag{ + Name: "routing-max-requests", + Value: 16, + EnvVars: []string{"ROUTING_MAX_REQUESTS"}, + Usage: "Maximum number of concurrent provider find requests, 0 for unlimited", + }, + &cli.IntFlag{ + Name: "routing-max-providers", + EnvVars: []string{"ROUTING_MAX_PROVIDERS"}, + Value: 0, + Usage: "Maximum number of providers to return for each provider find request, 0 for unlimited", + }, + &cli.DurationFlag{ + Name: "routing-max-timeout", + Value: 10 * time.Second, + EnvVars: []string{"ROUTING_MAX_TIMEOUT"}, + Usage: "Maximum time for routing to find the maximum number of providers", + }, } app.Commands = []*cli.Command{ @@ -540,6 +558,11 @@ share the same seed as long as the indexes are different. WALBytesPerSync: cctx.Int("pebble-wal-Bytes-per-sync"), MaxConcurrentCompactions: cctx.Int("pebble-max-concurrent-compactions"), WALMinSyncInterval: time.Second * time.Duration(cctx.Int("pebble-wal-min-sync-interval-sec")), + + // Routing ProviderQueryManager config + RoutingMaxRequests: cctx.Int("routing-max-requests"), + RoutingMaxProviders: cctx.Int("routing-max-providers"), + RoutingMaxTimeout: cctx.Duration("routing-max-timeout"), } var gnd *Node diff --git a/setup.go b/setup.go index 6261c59..2b6ca91 100644 --- a/setup.go +++ b/setup.go @@ -150,6 +150,11 @@ type Config struct { WALBytesPerSync int MaxConcurrentCompactions int WALMinSyncInterval time.Duration + + // ProviderQueryManager configuration. + RoutingMaxRequests int + RoutingMaxProviders int + RoutingMaxTimeout time.Duration } func SetupNoLibp2p(ctx context.Context, cfg Config, dnsCache *cachedDNS) (*Node, error) { diff --git a/setup_bitswap.go b/setup_bitswap.go index 5079b27..2e88cfd 100644 --- a/setup_bitswap.go +++ b/setup_bitswap.go @@ -28,7 +28,11 @@ func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routi // Custom query manager with the content router and the host // and our custom options to overwrite the default. - pqm, err := providerquerymanager.New(ctx, h, cr, providerquerymanager.WithMaxInProcessRequests(100)) + pqm, err := providerquerymanager.New(ctx, h, cr, + providerquerymanager.WithMaxInProcessRequests(cfg.RoutingMaxRequests), + providerquerymanager.WithMaxProviders(cfg.RoutingMaxProviders), + providerquerymanager.WithMaxTimeout(cfg.RoutingMaxTimeout), + ) if err != nil { panic(err) }