mirror of https://github.com/go-redis/redis.git
replacing the MaxActiveConns parameter with PoolSizeStrict
This commit is contained in:
parent
d8227214bc
commit
0bc34b8a83
|
@ -62,10 +62,10 @@ type Options struct {
|
|||
|
||||
PoolFIFO bool
|
||||
PoolSize int
|
||||
PoolSizeStrict bool
|
||||
PoolTimeout time.Duration
|
||||
MinIdleConns int
|
||||
MaxIdleConns int
|
||||
MaxActiveConns int
|
||||
ConnMaxIdleTime time.Duration
|
||||
ConnMaxLifetime time.Duration
|
||||
}
|
||||
|
@ -167,8 +167,8 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) {
|
|||
var poolExhausted bool
|
||||
|
||||
p.connsMu.Lock()
|
||||
if p.cfg.MaxActiveConns > 0 {
|
||||
poolExhausted = p.poolSize >= p.cfg.MaxActiveConns
|
||||
if p.cfg.PoolSizeStrict {
|
||||
poolExhausted = len(p.conns) >= p.poolSize
|
||||
}
|
||||
p.connsMu.Unlock()
|
||||
|
||||
|
|
14
options.go
14
options.go
|
@ -100,9 +100,12 @@ type Options struct {
|
|||
PoolFIFO bool
|
||||
// Base number of socket connections.
|
||||
// Default is 10 connections per every available CPU as reported by runtime.GOMAXPROCS.
|
||||
// If there is not enough connections in the pool, new connections will be allocated in excess of PoolSize,
|
||||
// you can limit it through MaxActiveConns
|
||||
// If there are not enough connections in the pool, new connections will be allocated beyond the PoolSize,
|
||||
// which can flood the server with connections under heavy load.
|
||||
// To enable standard pool behavior with overflow checking, use the PoolSizeStrict parameter
|
||||
PoolSize int
|
||||
// Enabling classic pool mode, when it is guaranteed that no more connections will open to the server than specified in PoolSize
|
||||
PoolSizeStrict bool
|
||||
// Amount of time client waits for connection if all connections
|
||||
// are busy before returning an error.
|
||||
// Default is ReadTimeout + 1 second.
|
||||
|
@ -114,9 +117,6 @@ type Options struct {
|
|||
// Maximum number of idle connections.
|
||||
// Default is 0. the idle connections are not closed by default.
|
||||
MaxIdleConns int
|
||||
// Maximum number of connections allocated by the pool at a given time.
|
||||
// When zero, there is no limit on the number of connections in the pool.
|
||||
MaxActiveConns int
|
||||
// ConnMaxIdleTime is the maximum amount of time a connection may be idle.
|
||||
// Should be less than server's timeout.
|
||||
//
|
||||
|
@ -458,10 +458,10 @@ func setupConnParams(u *url.URL, o *Options) (*Options, error) {
|
|||
o.WriteTimeout = q.duration("write_timeout")
|
||||
o.PoolFIFO = q.bool("pool_fifo")
|
||||
o.PoolSize = q.int("pool_size")
|
||||
o.PoolSizeStrict = q.bool("pool_size_strict")
|
||||
o.PoolTimeout = q.duration("pool_timeout")
|
||||
o.MinIdleConns = q.int("min_idle_conns")
|
||||
o.MaxIdleConns = q.int("max_idle_conns")
|
||||
o.MaxActiveConns = q.int("max_active_conns")
|
||||
if q.has("conn_max_idle_time") {
|
||||
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
|
||||
} else {
|
||||
|
@ -505,10 +505,10 @@ func newConnPool(
|
|||
},
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
PoolSizeStrict: opt.PoolSizeStrict,
|
||||
PoolTimeout: opt.PoolTimeout,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxIdleConns: opt.MaxIdleConns,
|
||||
MaxActiveConns: opt.MaxActiveConns,
|
||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||
})
|
||||
|
|
|
@ -76,11 +76,11 @@ type ClusterOptions struct {
|
|||
ContextTimeoutEnabled bool
|
||||
|
||||
PoolFIFO bool
|
||||
PoolSize int // applies per cluster node and not for the whole cluster
|
||||
PoolSize int // applies per cluster node and not for the whole cluster
|
||||
PoolSizeStrict bool // applies per cluster node and not for the whole cluster
|
||||
PoolTimeout time.Duration
|
||||
MinIdleConns int
|
||||
MaxIdleConns int
|
||||
MaxActiveConns int // applies per cluster node and not for the whole cluster
|
||||
ConnMaxIdleTime time.Duration
|
||||
ConnMaxLifetime time.Duration
|
||||
|
||||
|
@ -233,9 +233,9 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er
|
|||
o.WriteTimeout = q.duration("write_timeout")
|
||||
o.PoolFIFO = q.bool("pool_fifo")
|
||||
o.PoolSize = q.int("pool_size")
|
||||
o.PoolSizeStrict = q.bool("pool_size_strict")
|
||||
o.MinIdleConns = q.int("min_idle_conns")
|
||||
o.MaxIdleConns = q.int("max_idle_conns")
|
||||
o.MaxActiveConns = q.int("max_active_conns")
|
||||
o.PoolTimeout = q.duration("pool_timeout")
|
||||
o.ConnMaxLifetime = q.duration("conn_max_lifetime")
|
||||
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
|
||||
|
@ -284,10 +284,10 @@ func (opt *ClusterOptions) clientOptions() *Options {
|
|||
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
PoolSizeStrict: opt.PoolSizeStrict,
|
||||
PoolTimeout: opt.PoolTimeout,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxIdleConns: opt.MaxIdleConns,
|
||||
MaxActiveConns: opt.MaxActiveConns,
|
||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||
DisableIndentity: opt.DisableIndentity,
|
||||
|
|
4
ring.go
4
ring.go
|
@ -88,10 +88,10 @@ type RingOptions struct {
|
|||
PoolFIFO bool
|
||||
|
||||
PoolSize int
|
||||
PoolSizeStrict bool
|
||||
PoolTimeout time.Duration
|
||||
MinIdleConns int
|
||||
MaxIdleConns int
|
||||
MaxActiveConns int
|
||||
ConnMaxIdleTime time.Duration
|
||||
ConnMaxLifetime time.Duration
|
||||
|
||||
|
@ -155,10 +155,10 @@ func (opt *RingOptions) clientOptions() *Options {
|
|||
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
PoolSizeStrict: opt.PoolSizeStrict,
|
||||
PoolTimeout: opt.PoolTimeout,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxIdleConns: opt.MaxIdleConns,
|
||||
MaxActiveConns: opt.MaxActiveConns,
|
||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||
|
||||
|
|
|
@ -71,10 +71,10 @@ type FailoverOptions struct {
|
|||
PoolFIFO bool
|
||||
|
||||
PoolSize int
|
||||
PoolSizeStrict bool
|
||||
PoolTimeout time.Duration
|
||||
MinIdleConns int
|
||||
MaxIdleConns int
|
||||
MaxActiveConns int
|
||||
ConnMaxIdleTime time.Duration
|
||||
ConnMaxLifetime time.Duration
|
||||
|
||||
|
@ -107,10 +107,10 @@ func (opt *FailoverOptions) clientOptions() *Options {
|
|||
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
PoolSizeStrict: opt.PoolSizeStrict,
|
||||
PoolTimeout: opt.PoolTimeout,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxIdleConns: opt.MaxIdleConns,
|
||||
MaxActiveConns: opt.MaxActiveConns,
|
||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||
|
||||
|
@ -143,10 +143,10 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options {
|
|||
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
PoolSizeStrict: opt.PoolSizeStrict,
|
||||
PoolTimeout: opt.PoolTimeout,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxIdleConns: opt.MaxIdleConns,
|
||||
MaxActiveConns: opt.MaxActiveConns,
|
||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||
|
||||
|
@ -180,10 +180,10 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
|
|||
|
||||
PoolFIFO: opt.PoolFIFO,
|
||||
PoolSize: opt.PoolSize,
|
||||
PoolSizeStrict: opt.PoolSizeStrict,
|
||||
PoolTimeout: opt.PoolTimeout,
|
||||
MinIdleConns: opt.MinIdleConns,
|
||||
MaxIdleConns: opt.MaxIdleConns,
|
||||
MaxActiveConns: opt.MaxActiveConns,
|
||||
ConnMaxIdleTime: opt.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: opt.ConnMaxLifetime,
|
||||
|
||||
|
|
|
@ -45,10 +45,10 @@ type UniversalOptions struct {
|
|||
PoolFIFO bool
|
||||
|
||||
PoolSize int
|
||||
PoolSizeStrict bool
|
||||
PoolTimeout time.Duration
|
||||
MinIdleConns int
|
||||
MaxIdleConns int
|
||||
MaxActiveConns int
|
||||
ConnMaxIdleTime time.Duration
|
||||
ConnMaxLifetime time.Duration
|
||||
|
||||
|
@ -102,10 +102,10 @@ func (o *UniversalOptions) Cluster() *ClusterOptions {
|
|||
PoolFIFO: o.PoolFIFO,
|
||||
|
||||
PoolSize: o.PoolSize,
|
||||
PoolSizeStrict: o.PoolSizeStrict,
|
||||
PoolTimeout: o.PoolTimeout,
|
||||
MinIdleConns: o.MinIdleConns,
|
||||
MaxIdleConns: o.MaxIdleConns,
|
||||
MaxActiveConns: o.MaxActiveConns,
|
||||
ConnMaxIdleTime: o.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: o.ConnMaxLifetime,
|
||||
|
||||
|
@ -147,10 +147,10 @@ func (o *UniversalOptions) Failover() *FailoverOptions {
|
|||
|
||||
PoolFIFO: o.PoolFIFO,
|
||||
PoolSize: o.PoolSize,
|
||||
PoolSizeStrict: o.PoolSizeStrict,
|
||||
PoolTimeout: o.PoolTimeout,
|
||||
MinIdleConns: o.MinIdleConns,
|
||||
MaxIdleConns: o.MaxIdleConns,
|
||||
MaxActiveConns: o.MaxActiveConns,
|
||||
ConnMaxIdleTime: o.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: o.ConnMaxLifetime,
|
||||
|
||||
|
@ -189,10 +189,10 @@ func (o *UniversalOptions) Simple() *Options {
|
|||
|
||||
PoolFIFO: o.PoolFIFO,
|
||||
PoolSize: o.PoolSize,
|
||||
PoolSizeStrict: o.PoolSizeStrict,
|
||||
PoolTimeout: o.PoolTimeout,
|
||||
MinIdleConns: o.MinIdleConns,
|
||||
MaxIdleConns: o.MaxIdleConns,
|
||||
MaxActiveConns: o.MaxActiveConns,
|
||||
ConnMaxIdleTime: o.ConnMaxIdleTime,
|
||||
ConnMaxLifetime: o.ConnMaxLifetime,
|
||||
|
||||
|
|
Loading…
Reference in New Issue