Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track number of times pool reached zero available slots #5184

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions go/pools/resource_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type ResourcePool struct {
waitCount sync2.AtomicInt64
waitTime sync2.AtomicDuration
idleClosed sync2.AtomicInt64
exhausted sync2.AtomicInt64

capacity sync2.AtomicInt64
idleTimeout sync2.AtomicDuration
Expand Down Expand Up @@ -230,7 +231,9 @@ func (rp *ResourcePool) get(ctx context.Context) (resource Resource, err error)
}
rp.active.Add(1)
}
rp.available.Add(-1)
if rp.available.Add(-1) <= 0 {
rp.exhausted.Add(1)
}
rp.inUse.Add(1)
return wrapper.resource, err
}
Expand Down Expand Up @@ -334,7 +337,7 @@ func (rp *ResourcePool) SetIdleTimeout(idleTimeout time.Duration) {

// StatsJSON returns the stats in JSON format.
func (rp *ResourcePool) StatsJSON() string {
return fmt.Sprintf(`{"Capacity": %v, "Available": %v, "Active": %v, "InUse": %v, "MaxCapacity": %v, "WaitCount": %v, "WaitTime": %v, "IdleTimeout": %v, "IdleClosed": %v}`,
return fmt.Sprintf(`{"Capacity": %v, "Available": %v, "Active": %v, "InUse": %v, "MaxCapacity": %v, "WaitCount": %v, "WaitTime": %v, "IdleTimeout": %v, "IdleClosed": %v, "Exhausted": %v}`,
rp.Capacity(),
rp.Available(),
rp.Active(),
Expand All @@ -344,6 +347,7 @@ func (rp *ResourcePool) StatsJSON() string {
rp.WaitTime().Nanoseconds(),
rp.IdleTimeout().Nanoseconds(),
rp.IdleClosed(),
rp.Exhausted(),
)
}

Expand Down Expand Up @@ -392,3 +396,8 @@ func (rp *ResourcePool) IdleTimeout() time.Duration {
func (rp *ResourcePool) IdleClosed() int64 {
return rp.idleClosed.Get()
}

// Exhausted returns the number of times Available dropped below 1
func (rp *ResourcePool) Exhausted() int64 {
return rp.exhausted.Get()
}
10 changes: 5 additions & 5 deletions go/pools/resource_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func TestShrinking(t *testing.T) {
p.SetCapacity(3)
done <- true
}()
expected := `{"Capacity": 3, "Available": 0, "Active": 4, "InUse": 4, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0}`
expected := `{"Capacity": 3, "Available": 0, "Active": 4, "InUse": 4, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0, "Exhausted": 0}`
for i := 0; i < 10; i++ {
time.Sleep(10 * time.Millisecond)
stats := p.StatsJSON()
Expand All @@ -266,7 +266,7 @@ func TestShrinking(t *testing.T) {
p.Put(resources[i])
}
stats := p.StatsJSON()
expected = `{"Capacity": 3, "Available": 3, "Active": 3, "InUse": 0, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0}`
expected = `{"Capacity": 3, "Available": 3, "Active": 3, "InUse": 0, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0, "Exhausted": 0}`
if stats != expected {
t.Errorf(`expecting '%s', received '%s'`, expected, stats)
}
Expand Down Expand Up @@ -389,7 +389,7 @@ func TestClosing(t *testing.T) {
// Wait for goroutine to call Close
time.Sleep(10 * time.Millisecond)
stats := p.StatsJSON()
expected := `{"Capacity": 0, "Available": 0, "Active": 5, "InUse": 5, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0}`
expected := `{"Capacity": 0, "Available": 0, "Active": 5, "InUse": 5, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0, "Exhausted": 1}`
if stats != expected {
t.Errorf(`expecting '%s', received '%s'`, expected, stats)
}
Expand All @@ -409,7 +409,7 @@ func TestClosing(t *testing.T) {
}

stats = p.StatsJSON()
expected = `{"Capacity": 0, "Available": 0, "Active": 0, "InUse": 0, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0}`
expected = `{"Capacity": 0, "Available": 0, "Active": 0, "InUse": 0, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0, "Exhausted": 1}`
if stats != expected {
t.Errorf(`expecting '%s', received '%s'`, expected, stats)
}
Expand Down Expand Up @@ -563,7 +563,7 @@ func TestCreateFail(t *testing.T) {
t.Errorf("Expecting Failed, received %v", err)
}
stats := p.StatsJSON()
expected := `{"Capacity": 5, "Available": 5, "Active": 0, "InUse": 0, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0}`
expected := `{"Capacity": 5, "Available": 5, "Active": 0, "InUse": 0, "MaxCapacity": 5, "WaitCount": 0, "WaitTime": 0, "IdleTimeout": 1000000000, "IdleClosed": 0, "Exhausted": 0}`
if stats != expected {
t.Errorf(`expecting '%s', received '%s'`, expected, stats)
}
Expand Down
10 changes: 10 additions & 0 deletions go/vt/dbconnpool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func NewConnectionPool(name string, capacity int, idleTimeout time.Duration, dns
stats.NewCounterDurationFunc(name+"WaitTime", "Connection pool wait time", cp.WaitTime)
stats.NewGaugeDurationFunc(name+"IdleTimeout", "Connection pool idle timeout", cp.IdleTimeout)
stats.NewGaugeFunc(name+"IdleClosed", "Connection pool idle closed", cp.IdleClosed)
stats.NewCounterFunc(name+"Exhausted", "Number of times pool had zero available slots", cp.Exhausted)
return cp
}

Expand Down Expand Up @@ -355,3 +356,12 @@ func (cp *ConnectionPool) IdleClosed() int64 {
}
return p.IdleClosed()
}

// Exhausted returns the number of times available went to zero for the pool.
func (cp *ConnectionPool) Exhausted() int64 {
p := cp.pool()
if p == nil {
return 0
}
return p.Exhausted()
}
10 changes: 10 additions & 0 deletions go/vt/vttablet/tabletserver/connpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func New(
stats.NewCounterDurationFunc(name+"WaitTime", "Tablet server wait time", cp.WaitTime)
stats.NewGaugeDurationFunc(name+"IdleTimeout", "Tablet server idle timeout", cp.IdleTimeout)
stats.NewCounterFunc(name+"IdleClosed", "Tablet server conn pool idle closed", cp.IdleClosed)
stats.NewCounterFunc(name+"Exhausted", "Number of times pool had zero available slots", cp.Exhausted)
return cp
}

Expand Down Expand Up @@ -296,6 +297,15 @@ func (cp *Pool) IdleClosed() int64 {
return p.IdleClosed()
}

// Exhausted returns the number of times available went to zero for the pool.
func (cp *Pool) Exhausted() int64 {
p := cp.pool()
if p == nil {
return 0
}
return p.Exhausted()
}

func (cp *Pool) isCallerIDAppDebug(ctx context.Context) bool {
if cp.appDebugParams == nil || cp.appDebugParams.Uname == "" {
return false
Expand Down