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

infoschema, util: add table events_statements_summary_by_digest_history #13813

Merged
merged 11 commits into from
Dec 9, 2019

Conversation

djshow832
Copy link
Contributor

What problem does this PR solve?

Add a history table for statement summary for storing summaries that expired from events_statements_summary_by_digest.

What is changed and how it works?

Add a virtual table events_statements_summary_by_digest_history. When a summary expires from events_statements_summary_by_digest, put it into events_statements_summary_by_digest_history.
There's a system variable tidb_stmt_summary_history_size to control the history size for each summary.

Check List

Tests

  • Unit test
  • Manual test

Code changes

  • Has exported function/method change
  • Has interface methods change

Side effects

  • Possible performance regression
  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release note

  • Add a history table events_statements_summary_by_digest_history to store history summaries of events_statements_summary_by_digest.

@djshow832
Copy link
Contributor Author

/bench

@sre-bot
Copy link
Contributor

sre-bot commented Nov 29, 2019

Benchmark Report

Run Sysbench Performance Test on VMs

@@                               Benchmark Diff                               @@
================================================================================
--- tidb: 1c65ab936f270dd831b7923f7e1feb2b7ae6b4d1
+++ tidb: 5ed1ffbb6737f248dcb79dd64a3912194e9ab221
tikv: f6869aff3587ba0bcec47e099e57fdf11f63cbaf
pd: a87c9eb3181eb99cd6ae0128d07bad6d99b0c579
================================================================================
oltp_update_non_index:
    * QPS: 4717.87 ± 0.18% (std=5.80) delta: 0.08% (p=0.715)
    * Latency p50: 27.13 ± 0.00% (std=0.00) delta: -0.08%
    * Latency p99: 41.68 ± 4.11% (std=1.12) delta: -1.83%
            
oltp_insert:
    * QPS: 4779.43 ± 0.45% (std=14.57) delta: -0.03% (p=0.888)
    * Latency p50: 26.77 ± 0.47% (std=0.08) delta: 0.04%
    * Latency p99: 44.85 ± 8.36% (std=2.63) delta: 1.49%
            
oltp_read_write:
    * QPS: 15459.98 ± 0.58% (std=63.63) delta: 0.14% (p=0.679)
    * Latency p50: 165.91 ± 0.64% (std=0.72) delta: -0.17%
    * Latency p99: 300.92 ± 6.40% (std=13.55) delta: -1.40%
            
oltp_update_index:
    * QPS: 4267.52 ± 0.33% (std=9.61) delta: 0.32% (p=0.105)
    * Latency p50: 29.99 ± 0.32% (std=0.07) delta: -0.22%
    * Latency p99: 52.27 ± 2.39% (std=0.88) delta: -2.94%
            
oltp_point_select:
    * QPS: 40097.44 ± 0.25% (std=88.29) delta: 0.87% (p=0.004)
    * Latency p50: 3.19 ± 0.31% (std=0.01) delta: -0.85%
    * Latency p99: 9.82 ± 0.92% (std=0.09) delta: 0.00%
            

@djshow832
Copy link
Contributor Author

/run-all-tests

@djshow832
Copy link
Contributor Author

/run-unit-test

@codecov
Copy link

codecov bot commented Dec 2, 2019

Codecov Report

Merging #13813 into master will decrease coverage by 0.0124%.
The diff coverage is 92.4187%.

@@               Coverage Diff                @@
##             master     #13813        +/-   ##
================================================
- Coverage   80.1862%   80.1738%   -0.0125%     
================================================
  Files           481        481                
  Lines        120790     120593       -197     
================================================
- Hits          96857      96684       -173     
+ Misses        16224      16187        -37     
- Partials       7709       7722        +13

// historySize gets the history size for summaries.
func (ssMap *stmtSummaryByDigestMap) historySize() int {
size := int(atomic.LoadInt32(&ssMap.sysVars.historySize))
if size <= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant check?
Already do the check when setting the value. line#445

Copy link
Member

Choose a reason for hiding this comment

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

Agree, we should set history size in SetHistorySize at once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's normal that SetHistorySize is always called after bootstrap. But I do the check just in case that there would be any bug that prevents SetHistorySize be called after bootstrap, and it'll be a big problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I find out the problem.
If TiDB is just upgraded, global variables stored in TiKV doesn't include tidb_stmt_summary_history_size, so the loaded GlobalVariableCache doesn't include this variable, and then historySize won't be initialized.
I'll fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

func (ssMap *stmtSummaryByDigestMap) historySize() int {
size := int(atomic.LoadInt32(&ssMap.sysVars.historySize))
if size <= 0 {
size = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the default value of historySize is 1? Should be 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

or DefTiDBStmtSummaryHistorySize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default value is DefTiDBStmtSummaryHistorySize. Just in case that historySize is never set.

Copy link
Contributor Author

@djshow832 djshow832 Dec 4, 2019

Choose a reason for hiding this comment

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

Addressed. Now I make sure that historySize is always initialized, so this judgement is removed.

size = 0
}
}
if size > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

historySize will always not set to 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

after

set @@session.tidb_stmt_summary_history_size=0;
set @@global.tidb_stmt_summary_history_size=0;

, the historySize still not 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Actually, history includes the current summary. So historySize=1 indicates that there's only the current summary, and historySize=0 makes no sense.
I designed it like this because I wish xxx_history would be enough to see all the summaries.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed. Now historySize is allowed to be 0.

return ssbd
}

func (ssbd *stmtSummaryByDigest) add(sei *StmtExecInfo) {
func (ssbd *stmtSummaryByDigest) add(sei *StmtExecInfo, beginTime int64, historySize int) {
// Enclose this block in a function to ensure the lock will always be released.
Copy link
Contributor

Choose a reason for hiding this comment

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

return if historySize == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Addressed.

Copy link
Contributor

Choose a reason for hiding this comment

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

? how addressed?

@djshow832 djshow832 force-pushed the stmt_summary_history branch 3 times, most recently from eec2e5c to 09e49b3 Compare December 4, 2019 06:44
defer ssbd.Unlock()

var ssElement *stmtSummaryByDigestElement
ok := false
Copy link
Member

Choose a reason for hiding this comment

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

The logic is tricky here, please rename this variable and add some comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.


// `historySize` might be modified, so check expiration every time.
if historySize == 0 {
historySize = 1
Copy link
Member

Choose a reason for hiding this comment

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

This assignment looks weird. Why reassign historySize here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If historySize is 0, displayed history summaries in events_statements_summary_by_digest_history should be empty, but summary cannot be cleared, because table events_statements_summary_by_digest still needs it.
Alternatively, I can code for ssbd.history.Len() > historySize && ssbd.history.Len() > 1 {...}. But it looks also weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed.

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133 bb7133 added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 9, 2019
crazycs520
crazycs520 previously approved these changes Dec 9, 2019
Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@djshow832
Copy link
Contributor Author

/run-all-tests

@djshow832 djshow832 merged commit d439a57 into pingcap:master Dec 9, 2019
djshow832 added a commit to djshow832/tidb that referenced this pull request Dec 20, 2019
XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/util status/LGT1 Indicates that a PR has LGTM 1. type/usability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants