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

*: Optimize collecting executor runtime stats performance #58420

Merged
merged 34 commits into from
Dec 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
653da12
init
crazycs520 Dec 17, 2024
bdb93f3
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 18, 2024
0ed754e
update go.mod
crazycs520 Dec 18, 2024
ef81db4
refine
crazycs520 Dec 18, 2024
cf5a64f
refine
crazycs520 Dec 18, 2024
070002c
refine
crazycs520 Dec 18, 2024
ad1f92b
tiny refine basicCopRuntimeStats
crazycs520 Dec 18, 2024
0a9befc
Merge branch 'master' into opt-stats
crazycs520 Dec 18, 2024
44b7492
refine
crazycs520 Dec 18, 2024
04bbbbb
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 18, 2024
3cf93b2
refine
crazycs520 Dec 18, 2024
85e3789
refine
crazycs520 Dec 19, 2024
488e7ee
refine
crazycs520 Dec 19, 2024
6dcdff9
refine
crazycs520 Dec 19, 2024
4eaa03e
fix test
crazycs520 Dec 19, 2024
0d597d5
refine
crazycs520 Dec 19, 2024
abed82d
refine
crazycs520 Dec 19, 2024
50c769d
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 20, 2024
d6c0d2b
refine
crazycs520 Dec 20, 2024
4dba4bb
refine
crazycs520 Dec 20, 2024
ff3c685
update go.mod
crazycs520 Dec 20, 2024
f78e82c
refine CopRuntimeStats
crazycs520 Dec 20, 2024
c67d8c1
fix ci
crazycs520 Dec 23, 2024
32ed5a2
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 24, 2024
89764b3
fix ci lint
crazycs520 Dec 24, 2024
9554991
update go.mod
crazycs520 Dec 25, 2024
67189d9
update go.mod
crazycs520 Dec 25, 2024
9e227ef
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 25, 2024
0ffa2d9
make bazel_prepare
crazycs520 Dec 25, 2024
cdd8753
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 25, 2024
b33051c
fix
crazycs520 Dec 25, 2024
a7aaef2
refine
crazycs520 Dec 25, 2024
719ddad
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 25, 2024
5d5a593
Merge branch 'master' of https://github.com/pingcap/tidb into opt-stats
crazycs520 Dec 25, 2024
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
Prev Previous commit
Next Next commit
refine
Signed-off-by: crazycs520 <[email protected]>
  • Loading branch information
crazycs520 committed Dec 18, 2024

Verified

This commit was signed with the committer’s verified signature.
scala-steward Scala Steward
commit 070002cea9bb17fabbc0881f2f6aed0f8f19df94
26 changes: 18 additions & 8 deletions pkg/distsql/select_result.go
Original file line number Diff line number Diff line change
@@ -364,11 +364,11 @@ func (r *selectResult) fetchResp(ctx context.Context) error {
if ok {
copStats := hasStats.GetCopRuntimeStats()
if copStats != nil {
r.ctx.ExecDetails.MergeExecDetails(&copStats.ExecDetails, nil)
if err := r.updateCopRuntimeStats(ctx, copStats, resultSubset.RespTime()); err != nil {
return err
}
copStats.CopTime = duration
r.ctx.ExecDetails.MergeExecDetails(&copStats.ExecDetails, nil)
}
}
if len(r.selectResp.Chunks) != 0 {
@@ -478,7 +478,7 @@ func FillDummySummariesForTiFlashTasks(runtimeStatsColl *execdetails.RuntimeStat
dummySummary := &tipb.ExecutorExecutionSummary{TimeProcessedNs: &num, NumProducedRows: &num, NumIterations: &num, ExecutorId: nil}
for _, planID := range allPlanIDs {
if _, ok := recordedPlanIDs[planID]; !ok {
runtimeStatsColl.RecordOneCopTask(planID, storeType, callee, dummySummary)
runtimeStatsColl.RecordOneCopTask(planID, storeType, callee, nil, nil, dummySummary)
}
}
}
@@ -490,7 +490,7 @@ func recordExecutionSummariesForTiFlashTasks(runtimeStatsColl *execdetails.Runti
if detail != nil && detail.TimeProcessedNs != nil &&
detail.NumProducedRows != nil && detail.NumIterations != nil {
recordedPlanIDs[runtimeStatsColl.
RecordOneCopTask(-1, storeType, callee, detail)] = 0
RecordOneCopTask(-1, storeType, callee, nil, nil, detail)] = 0
}
}
FillDummySummariesForTiFlashTasks(runtimeStatsColl, callee, storeType, allPlanIDs, recordedPlanIDs)
@@ -520,9 +520,6 @@ func (r *selectResult) updateCopRuntimeStats(ctx context.Context, copStats *copr
}
}
r.stats.mergeCopRuntimeStats(copStats, respTime)
if len(r.copPlanIDs) > 0 {
r.ctx.RuntimeStatsColl.RecordCopStats(r.copPlanIDs[len(r.copPlanIDs)-1], r.storeType, copStats.ScanDetail, &copStats.TimeDetail)
}

// If hasExecutor is true, it means the summary is returned from TiFlash.
hasExecutor := false
@@ -545,6 +542,9 @@ func (r *selectResult) updateCopRuntimeStats(ctx context.Context, copStats *copr
r.ctx.CPUUsage.MergeTikvCPUTime(copStats.TimeDetail.ProcessTime)
}
if hasExecutor {
if len(r.copPlanIDs) > 0 {
r.ctx.RuntimeStatsColl.RecordCopStats(r.copPlanIDs[len(r.copPlanIDs)-1], r.storeType, copStats.ScanDetail, &copStats.TimeDetail)
}
recordExecutionSummariesForTiFlashTasks(r.ctx.RuntimeStatsColl, r.selectResp.GetExecutionSummaries(), callee, r.storeType, r.copPlanIDs)
} else {
// For cop task cases, we still need this protection.
@@ -560,11 +560,21 @@ func (r *selectResult) updateCopRuntimeStats(ctx context.Context, copStats *copr
return
}
for i, detail := range r.selectResp.GetExecutionSummaries() {
planID := r.copPlanIDs[i]
if i == len(r.copPlanIDs)-1 {
var summary *tipb.ExecutorExecutionSummary
if detail != nil && detail.TimeProcessedNs != nil &&
detail.NumProducedRows != nil && detail.NumIterations != nil {
summary = detail
}
r.ctx.RuntimeStatsColl.
RecordOneCopTask(planID, r.storeType, callee, copStats.ScanDetail, &copStats.TimeDetail, summary)
continue
}
if detail != nil && detail.TimeProcessedNs != nil &&
detail.NumProducedRows != nil && detail.NumIterations != nil {
planID := r.copPlanIDs[i]
r.ctx.RuntimeStatsColl.
RecordOneCopTask(planID, r.storeType, callee, detail)
RecordOneCopTask(planID, r.storeType, callee, nil, nil, detail)
}
}
}
2 changes: 1 addition & 1 deletion pkg/executor/internal/mpp/local_mpp_coordinator.go
Original file line number Diff line number Diff line change
@@ -640,7 +640,7 @@ func (c *localMppCoordinator) handleAllReports() error {
if detail != nil && detail.TimeProcessedNs != nil &&
detail.NumProducedRows != nil && detail.NumIterations != nil {
recordedPlanIDs[c.sessionCtx.GetSessionVars().StmtCtx.RuntimeStatsColl.
RecordOneCopTask(-1, kv.TiFlash, report.mppReq.Meta.GetAddress(), detail)] = 0
RecordOneCopTask(-1, kv.TiFlash, report.mppReq.Meta.GetAddress(), nil, nil, detail)] = 0
}
}
if ruDetailsRaw := c.ctx.Value(clientutil.RUDetailsCtxKey); ruDetailsRaw != nil {
38 changes: 22 additions & 16 deletions pkg/util/execdetails/execdetails.go
Original file line number Diff line number Diff line change
@@ -1660,29 +1660,15 @@ func getPlanIDFromExecutionSummary(summary *tipb.ExecutorExecutionSummary) (int,
}

// RecordOneCopTask records a specific cop tasks's execution detail.
func (e *RuntimeStatsColl) RecordOneCopTask(planID int, storeType kv.StoreType, address string, summary *tipb.ExecutorExecutionSummary) int {
// for TiFlash cop response, ExecutorExecutionSummary contains executor id, so if there is a valid executor id in
// summary, use it overwrite the planID
if id, valid := getPlanIDFromExecutionSummary(summary); valid {
planID = id
}
copStats := e.GetOrCreateCopStats(planID, storeType)
copStats.RecordOneCopTask(address, summary)
return planID
}

func (e *RuntimeStatsColl) RecordCopStats(planID int, storeType kv.StoreType, scan *util.ScanDetail, time *util.TimeDetail) {
func (e *RuntimeStatsColl) RecordOneCopTask(planID int, storeType kv.StoreType, address string, scan *util.ScanDetail, time *util.TimeDetail, summary *tipb.ExecutorExecutionSummary) int {
e.mu.Lock()
defer e.mu.Unlock()
copStats, ok := e.copStats[planID]
if !ok {
copStats = &CopRuntimeStats{
scanDetail: scan,
timeDetail: time,
storeType: storeType,
storeType: storeType,
}
e.copStats[planID] = copStats
return
}
if scan != nil {
if copStats.scanDetail == nil {
@@ -1698,6 +1684,26 @@ func (e *RuntimeStatsColl) RecordCopStats(planID int, storeType kv.StoreType, sc
copStats.timeDetail.Merge(time)
}
}
if summary != nil {
// for TiFlash cop response, ExecutorExecutionSummary contains executor id, so if there is a valid executor id in
// summary, use it overwrite the planID
id, valid := getPlanIDFromExecutionSummary(summary)
if valid && id != planID {
planID = id
copStats, ok = e.copStats[planID]
if !ok {
copStats = &CopRuntimeStats{
storeType: storeType,
}
e.copStats[planID] = copStats
}
}
copStats.RecordOneCopTask(address, summary)
}
return planID
}

func (e *RuntimeStatsColl) RecordCopStats(planID int, storeType kv.StoreType, scan *util.ScanDetail, time *util.TimeDetail) {
}

// ExistsRootStats checks if the planID exists in the rootStats collection.