Skip to content

Commit 028fa82

Browse files
committed
rm create delay and multiple spawners consts
1 parent 0031221 commit 028fa82

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed

internal/pool/defaults.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
package pool
22

3-
import "time"
4-
53
const (
64
DefaultLimit = 50
7-
8-
// defaultCreateRetryDelay specifies amount of time that spawner will wait
9-
// before retrying unsuccessful item create.
10-
defaultCreateRetryDelay = 500 * time.Millisecond
11-
12-
// defaultSpawnGoroutinesNumber specifies amount of spawnItems goroutines.
13-
// Having more than one spawner can potentially decrease warm-up time
14-
// and connections re-establishment time after connectivity failure.
15-
// Too high value will result in frequent connection establishment
16-
// attempts (see defaultCreateRetryDelay) during connectivity
17-
// issues which in some cases might not be desirable.
18-
defaultSpawnGoroutinesNumber = 2
195
)
206

217
var defaultTrace = &Trace{

internal/pool/pool.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,7 @@ func New[PT Item[T], T any](
202202
onChange: p.trace.OnChange,
203203
}
204204

205-
createCtx := xcontext.ValueOnly(ctx)
206-
for i := 0; i < defaultSpawnGoroutinesNumber; i++ {
207-
go p.spawnItems(createCtx)
208-
}
205+
go p.spawnItems(xcontext.ValueOnly(ctx))
209206

210207
return p
211208
}
@@ -227,15 +224,6 @@ func (p *Pool[PT, T]) spawnItems(ctx context.Context) {
227224
}
228225
// spawn was unsuccessful, need to try again.
229226
// token must always result in new item and not be lost.
230-
timer := time.NewTimer(defaultCreateRetryDelay)
231-
select {
232-
case <-p.done:
233-
timer.Stop()
234-
235-
return
236-
case <-timer.C:
237-
}
238-
timer.Stop()
239227
}
240228
}
241229
}
@@ -370,7 +358,6 @@ func (p *Pool[PT, T]) getItem(ctx context.Context) (_ PT, finalErr error) {
370358
if item != nil {
371359
if item.IsAlive() {
372360
// item is alive, return it
373-
p.stats.InUse().Inc()
374361

375362
return item, nil
376363
}
@@ -405,7 +392,6 @@ func (p *Pool[PT, T]) putItem(ctx context.Context, item PT) (finalErr error) {
405392
case <-ctx.Done():
406393
return xerrors.WithStackTrace(ctx.Err())
407394
default:
408-
p.stats.InUse().Dec()
409395
if item.IsAlive() {
410396
// put back in the queue
411397
select {
@@ -460,9 +446,11 @@ func (p *Pool[PT, T]) try(ctx context.Context, f func(ctx context.Context, item
460446

461447
return xerrors.WithStackTrace(err)
462448
}
449+
p.stats.InUse().Inc()
463450

464451
defer func() {
465452
_ = p.putItem(ctx, item)
453+
p.stats.InUse().Dec()
466454
}()
467455

468456
err = f(ctx, item)

0 commit comments

Comments
 (0)