Skip to content

Commit 0bc34b8

Browse files
committed
replacing the MaxActiveConns parameter with PoolSizeStrict
1 parent d822721 commit 0bc34b8

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

internal/pool/pool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ type Options struct {
6262

6363
PoolFIFO bool
6464
PoolSize int
65+
PoolSizeStrict bool
6566
PoolTimeout time.Duration
6667
MinIdleConns int
6768
MaxIdleConns int
68-
MaxActiveConns int
6969
ConnMaxIdleTime time.Duration
7070
ConnMaxLifetime time.Duration
7171
}
@@ -167,8 +167,8 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
167167
var poolExhausted bool
168168

169169
p.connsMu.Lock()
170-
if p.cfg.MaxActiveConns > 0 {
171-
poolExhausted = p.poolSize >= p.cfg.MaxActiveConns
170+
if p.cfg.PoolSizeStrict {
171+
poolExhausted = len(p.conns) >= p.poolSize
172172
}
173173
p.connsMu.Unlock()
174174

options.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ type Options struct {
100100
PoolFIFO bool
101101
// Base number of socket connections.
102102
// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
103-
// If there is not enough connections in the pool, new connections will be allocated in excess of PoolSize,
104-
// you can limit it through MaxActiveConns
103+
// If there are not enough connections in the pool, new connections will be allocated beyond the PoolSize,
104+
// which can flood the server with connections under heavy load.
105+
// To enable standard pool behavior with overflow checking, use the PoolSizeStrict parameter
105106
PoolSize int
107+
// Enabling classic pool mode, when it is guaranteed that no more connections will open to the server than specified in PoolSize
108+
PoolSizeStrict bool
106109
// Amount of time client waits for connection if all connections
107110
// are busy before returning an error.
108111
// Default is ReadTimeout + 1 second.
@@ -114,9 +117,6 @@ type Options struct {
114117
// Maximum number of idle connections.
115118
// Default is 0. the idle connections are not closed by default.
116119
MaxIdleConns int
117-
// Maximum number of connections allocated by the pool at a given time.
118-
// When zero, there is no limit on the number of connections in the pool.
119-
MaxActiveConns int
120120
// ConnMaxIdleTime is the maximum amount of time a connection may be idle.
121121
// Should be less than server's timeout.
122122
//
@@ -458,10 +458,10 @@ func setupConnParams(u *url.URL, o *Options) (*Options, error) {
458458
o.WriteTimeout = q.duration("write_timeout")
459459
o.PoolFIFO = q.bool("pool_fifo")
460460
o.PoolSize = q.int("pool_size")
461+
o.PoolSizeStrict = q.bool("pool_size_strict")
461462
o.PoolTimeout = q.duration("pool_timeout")
462463
o.MinIdleConns = q.int("min_idle_conns")
463464
o.MaxIdleConns = q.int("max_idle_conns")
464-
o.MaxActiveConns = q.int("max_active_conns")
465465
if q.has("conn_max_idle_time") {
466466
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
467467
} else {
@@ -505,10 +505,10 @@ func newConnPool(
505505
},
506506
PoolFIFO: opt.PoolFIFO,
507507
PoolSize: opt.PoolSize,
508+
PoolSizeStrict: opt.PoolSizeStrict,
508509
PoolTimeout: opt.PoolTimeout,
509510
MinIdleConns: opt.MinIdleConns,
510511
MaxIdleConns: opt.MaxIdleConns,
511-
MaxActiveConns: opt.MaxActiveConns,
512512
ConnMaxIdleTime: opt.ConnMaxIdleTime,
513513
ConnMaxLifetime: opt.ConnMaxLifetime,
514514
})

osscluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ type ClusterOptions struct {
7676
ContextTimeoutEnabled bool
7777

7878
PoolFIFO bool
79-
PoolSize int // applies per cluster node and not for the whole cluster
79+
PoolSize int // applies per cluster node and not for the whole cluster
80+
PoolSizeStrict bool // applies per cluster node and not for the whole cluster
8081
PoolTimeout time.Duration
8182
MinIdleConns int
8283
MaxIdleConns int
83-
MaxActiveConns int // applies per cluster node and not for the whole cluster
8484
ConnMaxIdleTime time.Duration
8585
ConnMaxLifetime time.Duration
8686

@@ -233,9 +233,9 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er
233233
o.WriteTimeout = q.duration("write_timeout")
234234
o.PoolFIFO = q.bool("pool_fifo")
235235
o.PoolSize = q.int("pool_size")
236+
o.PoolSizeStrict = q.bool("pool_size_strict")
236237
o.MinIdleConns = q.int("min_idle_conns")
237238
o.MaxIdleConns = q.int("max_idle_conns")
238-
o.MaxActiveConns = q.int("max_active_conns")
239239
o.PoolTimeout = q.duration("pool_timeout")
240240
o.ConnMaxLifetime = q.duration("conn_max_lifetime")
241241
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
@@ -284,10 +284,10 @@ func (opt *ClusterOptions) clientOptions() *Options {
284284

285285
PoolFIFO: opt.PoolFIFO,
286286
PoolSize: opt.PoolSize,
287+
PoolSizeStrict: opt.PoolSizeStrict,
287288
PoolTimeout: opt.PoolTimeout,
288289
MinIdleConns: opt.MinIdleConns,
289290
MaxIdleConns: opt.MaxIdleConns,
290-
MaxActiveConns: opt.MaxActiveConns,
291291
ConnMaxIdleTime: opt.ConnMaxIdleTime,
292292
ConnMaxLifetime: opt.ConnMaxLifetime,
293293
DisableIndentity: opt.DisableIndentity,

ring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ type RingOptions struct {
8888
PoolFIFO bool
8989

9090
PoolSize int
91+
PoolSizeStrict bool
9192
PoolTimeout time.Duration
9293
MinIdleConns int
9394
MaxIdleConns int
94-
MaxActiveConns int
9595
ConnMaxIdleTime time.Duration
9696
ConnMaxLifetime time.Duration
9797

@@ -155,10 +155,10 @@ func (opt *RingOptions) clientOptions() *Options {
155155

156156
PoolFIFO: opt.PoolFIFO,
157157
PoolSize: opt.PoolSize,
158+
PoolSizeStrict: opt.PoolSizeStrict,
158159
PoolTimeout: opt.PoolTimeout,
159160
MinIdleConns: opt.MinIdleConns,
160161
MaxIdleConns: opt.MaxIdleConns,
161-
MaxActiveConns: opt.MaxActiveConns,
162162
ConnMaxIdleTime: opt.ConnMaxIdleTime,
163163
ConnMaxLifetime: opt.ConnMaxLifetime,
164164

sentinel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ type FailoverOptions struct {
7171
PoolFIFO bool
7272

7373
PoolSize int
74+
PoolSizeStrict bool
7475
PoolTimeout time.Duration
7576
MinIdleConns int
7677
MaxIdleConns int
77-
MaxActiveConns int
7878
ConnMaxIdleTime time.Duration
7979
ConnMaxLifetime time.Duration
8080

@@ -107,10 +107,10 @@ func (opt *FailoverOptions) clientOptions() *Options {
107107

108108
PoolFIFO: opt.PoolFIFO,
109109
PoolSize: opt.PoolSize,
110+
PoolSizeStrict: opt.PoolSizeStrict,
110111
PoolTimeout: opt.PoolTimeout,
111112
MinIdleConns: opt.MinIdleConns,
112113
MaxIdleConns: opt.MaxIdleConns,
113-
MaxActiveConns: opt.MaxActiveConns,
114114
ConnMaxIdleTime: opt.ConnMaxIdleTime,
115115
ConnMaxLifetime: opt.ConnMaxLifetime,
116116

@@ -143,10 +143,10 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options {
143143

144144
PoolFIFO: opt.PoolFIFO,
145145
PoolSize: opt.PoolSize,
146+
PoolSizeStrict: opt.PoolSizeStrict,
146147
PoolTimeout: opt.PoolTimeout,
147148
MinIdleConns: opt.MinIdleConns,
148149
MaxIdleConns: opt.MaxIdleConns,
149-
MaxActiveConns: opt.MaxActiveConns,
150150
ConnMaxIdleTime: opt.ConnMaxIdleTime,
151151
ConnMaxLifetime: opt.ConnMaxLifetime,
152152

@@ -180,10 +180,10 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
180180

181181
PoolFIFO: opt.PoolFIFO,
182182
PoolSize: opt.PoolSize,
183+
PoolSizeStrict: opt.PoolSizeStrict,
183184
PoolTimeout: opt.PoolTimeout,
184185
MinIdleConns: opt.MinIdleConns,
185186
MaxIdleConns: opt.MaxIdleConns,
186-
MaxActiveConns: opt.MaxActiveConns,
187187
ConnMaxIdleTime: opt.ConnMaxIdleTime,
188188
ConnMaxLifetime: opt.ConnMaxLifetime,
189189

universal.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ type UniversalOptions struct {
4545
PoolFIFO bool
4646

4747
PoolSize int
48+
PoolSizeStrict bool
4849
PoolTimeout time.Duration
4950
MinIdleConns int
5051
MaxIdleConns int
51-
MaxActiveConns int
5252
ConnMaxIdleTime time.Duration
5353
ConnMaxLifetime time.Duration
5454

@@ -102,10 +102,10 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
102102
PoolFIFO: o.PoolFIFO,
103103

104104
PoolSize: o.PoolSize,
105+
PoolSizeStrict: o.PoolSizeStrict,
105106
PoolTimeout: o.PoolTimeout,
106107
MinIdleConns: o.MinIdleConns,
107108
MaxIdleConns: o.MaxIdleConns,
108-
MaxActiveConns: o.MaxActiveConns,
109109
ConnMaxIdleTime: o.ConnMaxIdleTime,
110110
ConnMaxLifetime: o.ConnMaxLifetime,
111111

@@ -147,10 +147,10 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
147147

148148
PoolFIFO: o.PoolFIFO,
149149
PoolSize: o.PoolSize,
150+
PoolSizeStrict: o.PoolSizeStrict,
150151
PoolTimeout: o.PoolTimeout,
151152
MinIdleConns: o.MinIdleConns,
152153
MaxIdleConns: o.MaxIdleConns,
153-
MaxActiveConns: o.MaxActiveConns,
154154
ConnMaxIdleTime: o.ConnMaxIdleTime,
155155
ConnMaxLifetime: o.ConnMaxLifetime,
156156

@@ -189,10 +189,10 @@ func (o *UniversalOptions) Simple() *Options {
189189

190190
PoolFIFO: o.PoolFIFO,
191191
PoolSize: o.PoolSize,
192+
PoolSizeStrict: o.PoolSizeStrict,
192193
PoolTimeout: o.PoolTimeout,
193194
MinIdleConns: o.MinIdleConns,
194195
MaxIdleConns: o.MaxIdleConns,
195-
MaxActiveConns: o.MaxActiveConns,
196196
ConnMaxIdleTime: o.ConnMaxIdleTime,
197197
ConnMaxLifetime: o.ConnMaxLifetime,
198198

0 commit comments

Comments
 (0)