Skip to content

Commit 7cdeb4b

Browse files
committed
Rename maxInProcessRequests to maxConcurrentFinds
1 parent 79a90ab commit 7cdeb4b

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

bitswap/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ func New(parent context.Context, network bsnet.BitSwapNetwork, bstore blockstore
7676
bpm := bsbpm.New()
7777
pm := bspm.New(ctx, peerQueueFactory, network.Self())
7878
pqm := bspqm.New(ctx, network,
79-
bspqm.WithMaxProvidersPerFind(opts.pqmMaxProvidersPerFind),
80-
bspqm.WithMaxInProcessRequests(opts.pqmMaxInProcessRequests))
79+
bspqm.WithMaxConcurrentFinds(opts.pqmMaxConcurrentFinds),
80+
bspqm.WithMaxProvidersPerFind(opts.pqmMaxProvidersPerFind))
8181

8282
sessionFactory := func(
8383
sessctx context.Context,
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
package providerquerymanager
22

33
const (
4-
defaultMaxProvidersPerFind = 10
5-
defaultMaxInProcessRequests = 6
4+
defaultMaxConcurrentFinds = 16
5+
defaultMaxProvidersPerFind = 10
66
)
77

88
type config struct {
9-
maxProvidersPerFind int
10-
maxInProcessRequests int
9+
maxConcurrentFinds int
10+
maxProvidersPerFind int
1111
}
1212

1313
type Option func(*config)
1414

1515
func getOpts(opts []Option) config {
1616
cfg := config{
17-
maxProvidersPerFind: defaultMaxProvidersPerFind,
18-
maxInProcessRequests: defaultMaxInProcessRequests,
17+
maxConcurrentFinds: defaultMaxConcurrentFinds,
18+
maxProvidersPerFind: defaultMaxProvidersPerFind,
1919
}
2020
for _, opt := range opts {
2121
opt(&cfg)
2222
}
2323
return cfg
2424
}
2525

26-
func WithMaxProvidersPerFind(n int) Option {
26+
func WithMaxConcurrentFinds(n int) Option {
2727
return func(c *config) {
2828
if n == 0 {
29-
n = defaultMaxProvidersPerFind
29+
n = defaultMaxConcurrentFinds
3030
}
31-
c.maxProvidersPerFind = n
31+
c.maxConcurrentFinds = n
3232
}
3333
}
3434

35-
func WithMaxInProcessRequests(n int) Option {
35+
func WithMaxProvidersPerFind(n int) Option {
3636
return func(c *config) {
3737
if n == 0 {
38-
n = defaultMaxInProcessRequests
38+
n = defaultMaxProvidersPerFind
3939
}
40-
c.maxInProcessRequests = n
40+
c.maxProvidersPerFind = n
4141
}
4242
}

bitswap/client/internal/providerquerymanager/providerquerymanager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (pqm *ProviderQueryManager) cancelProviderRequest(ctx context.Context, k ci
232232

233233
func (pqm *ProviderQueryManager) findProviderWorker() {
234234
// findProviderWorker just cycles through incoming provider queries one at
235-
// a time. There are maxInProcessRequests of these workers running
235+
// a time. There are pqm.opts.maxConcurrentFinds of these workers running
236236
// concurrently to let requests go in parallel but keep them rate limited.
237237
maxProviders := pqm.opts.maxProvidersPerFind
238238
for {
@@ -312,8 +312,8 @@ func (pqm *ProviderQueryManager) run() {
312312
}()
313313
}()
314314

315-
wg.Add(pqm.opts.maxInProcessRequests)
316-
for i := 0; i < pqm.opts.maxInProcessRequests; i++ {
315+
wg.Add(pqm.opts.maxConcurrentFinds)
316+
for i := 0; i < pqm.opts.maxConcurrentFinds; i++ {
317317
go func() {
318318
pqm.findProviderWorker()
319319
wg.Done()

bitswap/client/internal/providerquerymanager/providerquerymanager_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,29 +258,29 @@ func TestRateLimitingRequests(t *testing.T) {
258258
providerQueryManager := New(ctx, fpn)
259259
providerQueryManager.Startup()
260260

261-
maxInProcessRequests := providerQueryManager.opts.maxInProcessRequests
262-
keys := random.Cids(maxInProcessRequests + 1)
261+
maxConcurrentFinds := providerQueryManager.opts.maxConcurrentFinds
262+
keys := random.Cids(maxConcurrentFinds + 1)
263263
sessionCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
264264
defer cancel()
265265
var requestChannels []<-chan peer.ID
266-
for i := 0; i < maxInProcessRequests+1; i++ {
266+
for i := 0; i < maxConcurrentFinds+1; i++ {
267267
requestChannels = append(requestChannels, providerQueryManager.FindProvidersAsync(sessionCtx, keys[i]))
268268
}
269269
time.Sleep(20 * time.Millisecond)
270270
fpn.queriesMadeMutex.Lock()
271-
if fpn.liveQueries != maxInProcessRequests {
271+
if fpn.liveQueries != maxConcurrentFinds {
272272
t.Logf("Queries made: %d\n", fpn.liveQueries)
273273
t.Fatal("Did not limit parallel requests to rate limit")
274274
}
275275
fpn.queriesMadeMutex.Unlock()
276-
for i := 0; i < maxInProcessRequests+1; i++ {
276+
for i := 0; i < maxConcurrentFinds+1; i++ {
277277
for range requestChannels[i] {
278278
}
279279
}
280280

281281
fpn.queriesMadeMutex.Lock()
282282
defer fpn.queriesMadeMutex.Unlock()
283-
if fpn.queriesMade != maxInProcessRequests+1 {
283+
if fpn.queriesMade != maxConcurrentFinds+1 {
284284
t.Logf("Queries made: %d\n", fpn.queriesMade)
285285
t.Fatal("Did not make all separate requests")
286286
}

bitswap/client/optios.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type clientConfig struct {
1717
tracer tracer.Tracer
1818

1919
// ProviderQueryManager options.
20-
pqmMaxProvidersPerFind int
21-
pqmMaxInProcessRequests int
20+
pqmMaxConcurrentFinds int
21+
pqmMaxProvidersPerFind int
2222
}
2323

2424
// Option defines the functional option type that can be used to configure
@@ -92,14 +92,14 @@ func WithoutDuplicatedBlockStats() Option {
9292
}
9393
}
9494

95-
func WithPQMMaxProvidersPerFind(n int) Option {
95+
func WithPQMMaxConcurrentFinds(n int) Option {
9696
return func(c *clientConfig) {
97-
c.pqmMaxProvidersPerFind = n
97+
c.pqmMaxConcurrentFinds = n
9898
}
9999
}
100100

101-
func WithPQMMaxInProcessRequests(n int) Option {
101+
func WithPQMMaxProvidersPerFind(n int) Option {
102102
return func(c *clientConfig) {
103-
c.pqmMaxInProcessRequests = n
103+
c.pqmMaxProvidersPerFind = n
104104
}
105105
}

0 commit comments

Comments
 (0)