Skip to content

Commit

Permalink
add ruWaitDuration to RUDetails and update pd-client
Browse files Browse the repository at this point in the history
Signed-off-by: glorv <[email protected]>
  • Loading branch information
glorv committed Dec 4, 2023
1 parent d7d64ee commit 71e9be5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/prometheus/client_model v0.3.0
github.com/stretchr/testify v1.8.2
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a
github.com/tikv/pd/client v0.0.0-20231130081618-862eee18738e
github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2
github.com/twmb/murmur3 v1.1.3
go.etcd.io/etcd/api/v3 v3.5.10
go.etcd.io/etcd/client/v3 v3.5.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4=
github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM=
github.com/tikv/pd/client v0.0.0-20231130081618-862eee18738e h1:11cWLLmEreKof/VJi6LLQ+Jkav5ZqPJgeI+KX4pc/DE=
github.com/tikv/pd/client v0.0.0-20231130081618-862eee18738e/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ=
github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2 h1:7fnKwFC9pgiOolvnUnquEAb60liIpna+0hFRkopaOSg=
github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ=
github.com/twmb/murmur3 v1.1.3 h1:D83U0XYKcHRYwYIpBKf3Pks91Z0Byda/9SJ8B6EMRcA=
github.com/twmb/murmur3 v1.1.3/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.14.1
github.com/tikv/client-go/v2 v2.0.8-0.20231201024404-0ff16620f6c0
github.com/tikv/pd/client v0.0.0-20231130081618-862eee18738e
github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2
go.uber.org/goleak v1.3.0
)

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tikv/pd/client v0.0.0-20231130081618-862eee18738e h1:11cWLLmEreKof/VJi6LLQ+Jkav5ZqPJgeI+KX4pc/DE=
github.com/tikv/pd/client v0.0.0-20231130081618-862eee18738e/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ=
github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2 h1:7fnKwFC9pgiOolvnUnquEAb60liIpna+0hFRkopaOSg=
github.com/tikv/pd/client v0.0.0-20231204034622-259435d93ae2/go.mod h1:cd6zBqRM9aogxf26K8NnFRPVtq9BnRE59tKEpX8IaWQ=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
Expand Down
6 changes: 3 additions & 3 deletions internal/client/client_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func buildResourceControlInterceptor(
return next(target, req)
}

consumption, penalty, priority, err := resourceControlInterceptor.OnRequestWait(ctx, resourceGroupName, reqInfo)
consumption, penalty, waitDuration, priority, err := resourceControlInterceptor.OnRequestWait(ctx, resourceGroupName, reqInfo)
if err != nil {
return nil, err
}
Expand All @@ -118,7 +118,7 @@ func buildResourceControlInterceptor(
}
if ruDetails != nil {
detail := ruDetails.(*util.RUDetails)
detail.Update(consumption)
detail.Update(consumption, waitDuration)
}

resp, err := next(target, req)
Expand All @@ -130,7 +130,7 @@ func buildResourceControlInterceptor(
}
if ruDetails != nil {
detail := ruDetails.(*util.RUDetails)
detail.Update(consumption)
detail.Update(consumption, time.Duration(0))
}
}
return resp, err
Expand Down
26 changes: 18 additions & 8 deletions util/execdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,35 +689,39 @@ func (rd *ResolveLockDetail) Merge(resolveLock *ResolveLockDetail) {

// RUDetails contains RU detail info.
type RUDetails struct {
readRU *uatomic.Float64
writeRU *uatomic.Float64
readRU *uatomic.Float64
writeRU *uatomic.Float64
ruWaitDuration *uatomic.Duration
}

// NewRUDetails creates a new RUDetails.
func NewRUDetails() *RUDetails {
return &RUDetails{
readRU: uatomic.NewFloat64(0),
writeRU: uatomic.NewFloat64(0),
readRU: uatomic.NewFloat64(0),
writeRU: uatomic.NewFloat64(0),
ruWaitDuration: uatomic.NewDuration(0),
}
}

// Clone implements the RuntimeStats interface.
func (rd *RUDetails) Clone() *RUDetails {
return &RUDetails{
readRU: uatomic.NewFloat64(rd.readRU.Load()),
writeRU: uatomic.NewFloat64(rd.writeRU.Load()),
readRU: uatomic.NewFloat64(rd.readRU.Load()),
writeRU: uatomic.NewFloat64(rd.writeRU.Load()),
ruWaitDuration: uatomic.NewDuration(rd.ruWaitDuration.Load()),
}
}

// Merge implements the RuntimeStats interface.
func (rd *RUDetails) Merge(other *RUDetails) {
rd.readRU.Add(other.readRU.Load())
rd.writeRU.Add(other.writeRU.Load())
rd.ruWaitDuration.Add(other.ruWaitDuration.Load())
}

// String implements fmt.Stringer interface.
func (rd *RUDetails) String() string {
return fmt.Sprintf("RRU:%f, WRU:%f", rd.readRU.Load(), rd.writeRU.Load())
return fmt.Sprintf("RRU:%f, WRU:%f, WaitDuration:%v", rd.readRU.Load(), rd.writeRU.Load(), rd.ruWaitDuration.Load())
}

// RRU returns the read RU.
Expand All @@ -730,11 +734,17 @@ func (rd *RUDetails) WRU() float64 {
return rd.writeRU.Load()
}

// RUWaitDuration returns the time duration waiting for available RU.
func (rd *RUDetails) RUWaitDuration() time.Duration {
return rd.ruWaitDuration.Load()
}

// Update updates the RU runtime stats with the given consumption info.
func (rd *RUDetails) Update(consumption *rmpb.Consumption) {
func (rd *RUDetails) Update(consumption *rmpb.Consumption, waitDuration time.Duration) {
if rd == nil || consumption == nil {
return
}
rd.readRU.Add(consumption.RRU)
rd.writeRU.Add(consumption.WRU)
rd.ruWaitDuration.Add(waitDuration)
}

0 comments on commit 71e9be5

Please sign in to comment.