Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce default number of routing in-process requests #793

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions bitswap/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ func WithoutDuplicatedBlockStats() Option {
// lookups. The bitswap default ProviderQueryManager uses these options, which
// may be more conservative than the ProviderQueryManager defaults:
//
// - WithMaxInProcessRequests(16)
// - WithMaxProviders(10)
// - WithMaxTimeout(10 *time.Second)
// - WithMaxProviders(defaults.BitswapClientDefaultMaxProviders)
//
// To use a custom ProviderQueryManager, set to false and wrap directly the
// content router provided with the WithContentRouting() option. Only takes
Expand Down Expand Up @@ -196,9 +194,7 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, providerFinder Pr
if bs.providerFinder != nil && bs.defaultProviderQueryManager {
// network can do dialing.
pqm, err := rpqm.New(network, bs.providerFinder,
rpqm.WithMaxInProcessRequests(16),
rpqm.WithMaxProviders(10),
rpqm.WithMaxTimeout(10*time.Second))
rpqm.WithMaxProviders(defaults.BitswapClientDefaultMaxProviders))
if err != nil {
// Should not be possible to hit this
panic(err)
Expand Down
3 changes: 3 additions & 0 deletions bitswap/internal/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const (
// broadcasting outstanding wants for the first time.
ProvSearchDelay = time.Second

// Maximum number of providers that are looked up per find request by the
// default bitswap client. 0 value means unlimited.
BitswapClientDefaultMaxProviders = 10
// Number of concurrent workers in decision engine that process requests to the blockstore
BitswapEngineBlockstoreWorkerCount = 128
// the total number of simultaneous threads sending outgoing messages
Expand Down
30 changes: 18 additions & 12 deletions routing/providerquerymanager/providerquerymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ import (
var log = logging.Logger("routing/provqrymgr")

const (
defaultMaxInProcessRequests = 16
defaultMaxProviders = 0
defaultTimeout = 10 * time.Second
// DefaultMaxInProcessRequests is the default maximum number of requests
// that are processed concurrently. A value of 0 means unlimited.
DefaultMaxInProcessRequests = 8
// DefaultMaxProviders is the default maximum number of providers that are
// looked up per find request. 0 value means unlimited.
DefaultMaxProviders = 0
// DefaultTimeout is the limit on the amount of time to spend waiting for
// the maximum number of providers from a find request.
DefaultTimeout = 10 * time.Second
gammazero marked this conversation as resolved.
Show resolved Hide resolved
)

type inProgressRequestStatus struct {
Expand Down Expand Up @@ -112,19 +118,19 @@ func WithMaxTimeout(timeout time.Duration) Option {
}
}

// WithMaxInProcessRequests is the maximum number of requests that can be
// processed in parallel. If this is 0, then the number is unlimited. Default
// is defaultMaxInProcessRequests (16).
gammazero marked this conversation as resolved.
Show resolved Hide resolved
// WithMaxInProcessRequests sets maximum number of requests that are processed
// concurrently. A value of 0 means unlimited. Default is
// DefaultMaxInProcessRequests.
func WithMaxInProcessRequests(count int) Option {
return func(mgr *ProviderQueryManager) error {
mgr.maxInProcessRequests = count
return nil
}
}

// WithMaxProviders is the maximum number of providers that will be looked up
// per query. We only return providers that we can connect to. Defaults to 0,
// which means unbounded.
// WithMaxProviders sets the maximum number of providers that are looked up per
// find request. Only providers that we can connect to are returned. Defaults
// to 0, which means unlimited.
func WithMaxProviders(count int) Option {
return func(mgr *ProviderQueryManager) error {
mgr.maxProviders = count
Expand All @@ -140,9 +146,9 @@ func New(dialer ProviderQueryDialer, router ProviderQueryRouter, opts ...Option)
dialer: dialer,
router: router,
providerQueryMessages: make(chan providerQueryMessage),
findProviderTimeout: defaultTimeout,
maxInProcessRequests: defaultMaxInProcessRequests,
maxProviders: defaultMaxProviders,
findProviderTimeout: DefaultTimeout,
maxInProcessRequests: DefaultMaxInProcessRequests,
maxProviders: DefaultMaxProviders,
}

for _, o := range opts {
Expand Down
Loading