Skip to content

Commit

Permalink
perf: improve memory efficiency of the connection pool
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Oct 20, 2024
1 parent 28fba8c commit a910fe8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ func newPool(cap int, dead wire, makeFn func() wire) *pool {

return &pool{
size: 0,
cap: cap,
dead: dead,
make: makeFn,
list: make([]wire, 0, cap),
list: make([]wire, 0, 4),
cond: sync.NewCond(&sync.Mutex{}),
}
}
Expand All @@ -22,12 +23,13 @@ type pool struct {
make func() wire
list []wire
size int
cap int
down bool
}

func (p *pool) Acquire() (v wire) {
p.cond.L.Lock()
for len(p.list) == 0 && p.size == cap(p.list) && !p.down {
for len(p.list) == 0 && p.size == p.cap && !p.down {
p.cond.Wait()
}
if p.down {
Expand Down
2 changes: 1 addition & 1 deletion rueidis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
// DefaultRingScale is the default value of ClientOption.RingScaleEachConn, which results into having a ring of size 2^10 for each connection
DefaultRingScale = 10
// DefaultPoolSize is the default value of ClientOption.BlockingPoolSize
DefaultPoolSize = 1000
DefaultPoolSize = 1024
// DefaultBlockingPipeline is the default value of ClientOption.BlockingPipeline
DefaultBlockingPipeline = 2000
// DefaultDialTimeout is the default value of ClientOption.Dialer.Timeout
Expand Down

0 comments on commit a910fe8

Please sign in to comment.