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

*: add max/avg cop response time for TableReader, IndexReader and IndexLookupReader. #12003

Merged
merged 19 commits into from
Sep 11, 2019

Conversation

lzmhhh123
Copy link
Contributor

@lzmhhh123 lzmhhh123 commented Sep 3, 2019

What problem does this PR solve?

fix #12148

When explain analyze only shows the running time in coprocessor, but it doesn't consider the network trans time, encode time in coprocessor and decode time in tidb. So this PR adds a max coprocessor response time to fetch more information.

tidb(localhost:4000) > desc analyze select /*+ TIDB_INLJ(t, s) */ t.a from t left join s on t.a = s.a order by t.a desc;
+--------------------------+-------+------+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+----------------+
| id                       | count | task | operator info                                                                                | execution info                                                                                                                 | memory         |
+--------------------------+-------+------+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+----------------+
| Projection_16            | 3.75  | root | test.t.a                                                                                     | time:778.424µs, loops:2, rows:5                                                                                                | N/A            |
| └─IndexJoin_21           | 3.75  | root | left outer join, inner:IndexReader_20, outer key:test.t.a, inner key:test.s.a                | time:776.036µs, loops:2, rows:5                                                                                                | 21.19140625 KB |
|   ├─IndexReader_23       | 3.00  | root | index:IndexScan_22                                                                           | time:18.45µs, loops:3, rows:3, cop resp time max:213.883µs, min:213.883µs, avg:213.883µs, p80:213.883µs, p95:213.883µs         | 155 Bytes      |
|   │ └─IndexScan_22       | 3.00  | cop  | table:t, index:a, range:[NULL,+inf], keep order:true, desc                                   | time:131.697µs, loops:4, rows:3                                                                                                | N/A            |
|   └─IndexReader_20       | 0.01  | root | index:Selection_19                                                                           | time:312.121µs, loops:2, rows:4, cop resp time max:248.136µs, min:248.136µs, avg:248.136µs, p80:248.136µs, p95:248.136µs       | 190 Bytes      |
|     └─Selection_19       | 0.01  | cop  | not(isnull(test.s.a))                                                                        | time:107.07µs, loops:5, rows:4                                                                                                 | N/A            |
|       └─IndexScan_18     | 0.01  | cop  | table:s, index:a, range: decided by [eq(test.s.a, test.t.a)], keep order:false, stats:pseudo | time:95.173µs, loops:5, rows:4                                                                                                 | N/A            |
+--------------------------+-------+------+----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------+----------------+
7 rows in set (0.02 sec)

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change
  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity

@lzmhhh123 lzmhhh123 changed the title *: add max cop response time for TableReader, IndexReader and IndexLookupReader. *: add max/avg cop response time for TableReader, IndexReader and IndexLookupReader. Sep 3, 2019
@qw4990 qw4990 self-requested a review September 4, 2019 05:05
distsql/select_result.go Outdated Show resolved Hide resolved
Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

The execution format in Cop task is proc max:%v, min:%v, p80:%v, p95:%v, rows:%v, iters:%v, tasks:%v
Could you unify them?

@lzmhhh123
Copy link
Contributor Author

/run-unit-test

@codecov
Copy link

codecov bot commented Sep 4, 2019

Codecov Report

Merging #12003 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #12003   +/-   ##
===========================================
  Coverage   81.3524%   81.3524%           
===========================================
  Files           453        453           
  Lines         97450      97450           
===========================================
  Hits          79278      79278           
  Misses        12510      12510           
  Partials       5662       5662

@lzmhhh123
Copy link
Contributor Author

/run-all-tests

}

// RecordOneCopTask record once cop response time to update maxCopRespTime
func (rrs *ReaderRuntimeStats) RecordOneCopTask(t time.Duration) {
Copy link
Member

Choose a reason for hiding this comment

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

no need to export this function.

defer e.mu.Unlock()
stats, exists := e.readerStats[planID]
if !exists {
stats = &ReaderRuntimeStats{copRespTime: make([]time.Duration, 0, 20)}
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why setting the slice capacity to 20?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a casual value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any idea or just set it zero.

util/execdetails/execdetails.go Show resolved Hide resolved
}
switch p.(type) {
case *PhysicalTableReader, *PhysicalIndexReader, *PhysicalIndexLookUpReader:
if runtimeStatsColl.GetReaderStats(explainID) != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if runtimeStatsColl.GetReaderStats(explainID) != nil {
if s := runtimeStatsColl.GetReaderStats(explainID); s != nil {

switch p.(type) {
case *PhysicalTableReader, *PhysicalIndexReader, *PhysicalIndexLookUpReader:
if runtimeStatsColl.GetReaderStats(explainID) != nil {
analyzeInfo += ", " + runtimeStatsColl.GetReaderStats(explainID).String()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
analyzeInfo += ", " + runtimeStatsColl.GetReaderStats(explainID).String()
analyzeInfo += ", " + s.String()

@disksing
Copy link
Contributor

em, no proc time any more?

sort.Slice(rrs.copRespTime, func(i, j int) bool {
return rrs.copRespTime[i] < rrs.copRespTime[j]
})
s := "cop resp time "
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it shorter? How about the same form as proc time and call it rpc time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's OK.

@lzmhhh123
Copy link
Contributor Author

em, no proc time any more?

In mocktikv. It doesn't have proc time.
In tikv or tiflash, it has.

tidb(localhost:4000) > desc analyze select /*+ read_from_storage(tiflash[lineitem]) */ * from lineitem;
+-------------------+------------+--------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+-----$-----------------+
| id                | count      | task         | operator info                                       | execution info                                                                                                                                           | memo$y                |
+-------------------+------------+--------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+-----$-----------------+
| TableReader_5     | 6001215.00 | root         | data:TableScan_4                                    | time:50.560209007s, loops:5862, rows:6001215, cop resp time max:23.160214791s, min:3.868990591s, avg:10.995373571s, p80:22.553894442s, p95:22.684954285s | 163.83687496185303 MB |
| └─TableScan_4     | 6001215.00 | cop[tiflash] | table:lineitem, range:[-inf,+inf], keep order:false | proc max:1.176744s, min:382.01ms, p80:1.03543s, p95:1.093618s, rows:6001215, iters:796, tasks:63                                                         | N/A                 |
+-------------------+------------+--------------+-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
2 rows in set (50.81 sec)

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

zz-jason
zz-jason previously approved these changes Sep 11, 2019
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. labels Sep 11, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 11, 2019

Your auto merge job has been accepted, waiting for 12009, 12085

@lzmhhh123
Copy link
Contributor Author

@zz-jason Prev auto-merge job caused conflicts. The approvement is dismissed by merge master.

@lzmhhh123
Copy link
Contributor Author

/merge

@sre-bot
Copy link
Contributor

sre-bot commented Sep 11, 2019

/run-all-tests

@sre-bot sre-bot merged commit 39e9c9f into pingcap:master Sep 11, 2019
@lzmhhh123 lzmhhh123 deleted the dev/add_cop_resp_time branch September 11, 2019 12:37
lzmhhh123 added a commit to lzmhhh123/tidb that referenced this pull request Jan 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show coprocessor request duration in explain analyze
7 participants