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

stmtsummary: tiny optimize by avoiding unnecessary calculations #58562

Merged
merged 2 commits into from
Dec 27, 2024
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
2 changes: 1 addition & 1 deletion pkg/executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ func (a *ExecStmt) SummaryStmt(succ bool) {
}

execDetail := stmtCtx.GetExecDetails()
copTaskInfo := stmtCtx.CopTasksDetails()
copTaskInfo := stmtCtx.CopTasksSummary()
memMax := sessVars.MemTracker.MaxConsumed()
diskMax := sessVars.DiskTracker.MaxConsumed()
var stmtDetail execdetails.StmtExecDetails
Expand Down
30 changes: 30 additions & 0 deletions pkg/util/execdetails/execdetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,25 @@ func (s *SyncExecDetails) CopTasksDetails() *CopTasksDetails {
return d
}

// CopTasksSummary returns some summary information of cop-tasks for statement summary.
func (s *SyncExecDetails) CopTasksSummary() *CopTasksSummary {
s.mu.Lock()
defer s.mu.Unlock()
n := s.detailsSummary.NumCopTasks
if n == 0 {
return nil
}
return &CopTasksSummary{
NumCopTasks: n,
MaxProcessAddress: s.detailsSummary.ProcessTimePercentile.GetMax().Addr,
MaxProcessTime: s.detailsSummary.ProcessTimePercentile.GetMax().D,
TotProcessTime: s.execDetails.TimeDetail.ProcessTime,
MaxWaitAddress: s.detailsSummary.WaitTimePercentile.GetMax().Addr,
MaxWaitTime: s.detailsSummary.WaitTimePercentile.GetMax().D,
TotWaitTime: s.execDetails.TimeDetail.WaitTime,
}
}

// CopTasksDetails collects some useful information of cop-tasks during execution.
type CopTasksDetails struct {
NumCopTasks int
Expand All @@ -535,6 +554,17 @@ type CopTasksDetails struct {
TotBackoffTimes map[string]int
}

// CopTasksSummary collects some summary information of cop-tasks for statement summary.
type CopTasksSummary struct {
NumCopTasks int
MaxProcessAddress string
MaxProcessTime time.Duration
TotProcessTime time.Duration
MaxWaitAddress string
MaxWaitTime time.Duration
TotWaitTime time.Duration
}

// ToZapFields wraps the CopTasksDetails as zap.Fileds.
func (d *CopTasksDetails) ToZapFields() (fields []zap.Field) {
if d == nil || d.NumCopTasks == 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/stmtsummary/statement_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ type StmtExecInfo struct {
ParseLatency time.Duration
CompileLatency time.Duration
StmtCtx *stmtctx.StatementContext
CopTasks *execdetails.CopTasksDetails
CopTasks *execdetails.CopTasksSummary
ExecDetail execdetails.ExecDetails
MemMax int64
DiskMax int64
Expand Down
18 changes: 3 additions & 15 deletions pkg/util/stmtsummary/statement_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,11 @@ func TestAddStatement(t *testing.T) {
TotalLatency: 20000,
ParseLatency: 200,
CompileLatency: 2000,
CopTasks: &execdetails.CopTasksDetails{
CopTasks: &execdetails.CopTasksSummary{
NumCopTasks: 20,
AvgProcessTime: 2000,
P90ProcessTime: 20000,
MaxProcessAddress: "200",
MaxProcessTime: 25000,
TotProcessTime: 40000,
AvgWaitTime: 200,
P90WaitTime: 2000,
MaxWaitAddress: "201",
MaxWaitTime: 2500,
TotWaitTime: 40000,
Expand Down Expand Up @@ -334,15 +330,11 @@ func TestAddStatement(t *testing.T) {
TotalLatency: 1000,
ParseLatency: 50,
CompileLatency: 500,
CopTasks: &execdetails.CopTasksDetails{
CopTasks: &execdetails.CopTasksSummary{
NumCopTasks: 2,
AvgProcessTime: 100,
P90ProcessTime: 300,
MaxProcessAddress: "300",
MaxProcessTime: 350,
TotProcessTime: 200,
AvgWaitTime: 20,
P90WaitTime: 200,
MaxWaitAddress: "301",
MaxWaitTime: 250,
TotWaitTime: 40,
Expand Down Expand Up @@ -655,15 +647,11 @@ func generateAnyExecInfo() *StmtExecInfo {
TotalLatency: 10000,
ParseLatency: 100,
CompileLatency: 1000,
CopTasks: &execdetails.CopTasksDetails{
CopTasks: &execdetails.CopTasksSummary{
NumCopTasks: 10,
AvgProcessTime: 1000,
P90ProcessTime: 10000,
MaxProcessAddress: "127",
MaxProcessTime: 15000,
TotProcessTime: 10000,
AvgWaitTime: 100,
P90WaitTime: 1000,
MaxWaitAddress: "128",
MaxWaitTime: 1500,
TotWaitTime: 1000,
Expand Down
6 changes: 1 addition & 5 deletions pkg/util/stmtsummary/v2/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,10 @@ func GenerateStmtExecInfo4Test(digest string) *stmtsummary.StmtExecInfo {
TotalLatency: 10000,
ParseLatency: 100,
CompileLatency: 1000,
CopTasks: &execdetails.CopTasksDetails{
CopTasks: &execdetails.CopTasksSummary{
NumCopTasks: 10,
AvgProcessTime: 1000,
P90ProcessTime: 10000,
MaxProcessAddress: "127",
MaxProcessTime: 15000,
AvgWaitTime: 100,
P90WaitTime: 1000,
MaxWaitAddress: "128",
MaxWaitTime: 1500,
},
Expand Down