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

*: collect execution details and output them in slow query log #7302

Merged
merged 5 commits into from
Aug 10, 2018

Conversation

coocood
Copy link
Member

@coocood coocood commented Aug 7, 2018

Collect each execution detail in coprocessor request into StatementContext.
Output them in slow query log.

What have you changed? (mandatory)

Collect each execution detail in coprocessor request into StatementContext.
Output them in slow query log.

What is the type of the changes? (mandatory)

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested? (mandatory)

manual and unit test

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

YES

Does this PR affect tidb-ansible update? (mandatory)

NO

Does this PR need to be added to the release notes? (mandatory)

YES

release note:
include execution details in slow query log

Refer to a related PR or issue link (optional)

Benchmark result if necessary (optional)

Add a few positive/negative examples (optional)

Collect each execution detail in coprocessor request into StatementContext.
So we can include them in slow query log.
@coocood coocood added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Aug 7, 2018
@coocood
Copy link
Member Author

coocood commented Aug 7, 2018

@zz-jason @shenli @tiancaiamao PTAL

@coocood coocood added the type/enhancement The issue or PR belongs to an enhancement. label Aug 7, 2018
}

// String implements the fmt.Stringer interface.
func (d ExecDetails) String() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we take a try to implement fmt.Formatter way instead of String() for better performance?

IMHO, the ideal way to log struct is direct transform struct into file system buffer, and we shouldn't struct->string->fmt.Sprintf. it seems that Formatter interface is what we want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only called once for a slow query, I think we don't need to worry about the performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatter is not necessary, we can use a string builder for it.
https://godoc.org/strings#Builder

sc.mu.execDetails.WaitTime += details.WaitTime
sc.mu.execDetails.BackoffTime += details.BackoffTime
sc.mu.execDetails.RequestCount++
sc.mu.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we need to make execDetails r/w lock-free?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the lock contention is very low.

@zz-jason zz-jason self-assigned this Aug 8, 2018
parts = append(parts, fmt.Sprintf("request_count:%d", d.RequestCount))
}
if d.TotalKeys > 0 {
parts = append(parts, fmt.Sprintf("total_keys:%d", d.TotalKeys))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does "total_keys" and "processed_keys" mean?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can explain them in documents later.

}
r.feedback.Update(re.result.GetStartKey(), r.selectResp.OutputCounts)
r.partialCount++
sc.MergeExecDetails(re.result.GetExecDetails())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to print execution details for every coprocessor request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes there are hundreds of coprocessor requests, then the SLOW_QUERY log would be unreadable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometime there is a data skew in some key ranges, and this data skew can slow down the coprocessor performance and cause other coprocessor request waits for processing.

if we merge all the coprocessor request for a user query, we can not recognize the data skew.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we maintain a max?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem this PR solves is to distinguish culprit queries among SLOW queries.
The total time is enough for this purpose.

@zz-jason
Copy link
Member

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 10, 2018
@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao tiancaiamao added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 10, 2018
tiancaiamao
tiancaiamao previously approved these changes Aug 10, 2018
@coocood
Copy link
Member Author

coocood commented Aug 10, 2018

/run-all-tests

@lysu lysu merged commit e3952d6 into pingcap:master Aug 10, 2018
@coocood coocood deleted the collect-total-time branch August 11, 2018 06:19
coocood added a commit to coocood/tidb that referenced this pull request Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants