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

executor: add some memory tables to observe memory usage #38452

Merged
merged 23 commits into from
Oct 28, 2022

Conversation

wshwsh12
Copy link
Contributor

@wshwsh12 wshwsh12 commented Oct 13, 2022

What problem does this PR solve?

Issue Number: ref #37816
Problem Summary:

What is changed and how it works?

Add two memory usage information_schema.MEMORY_USAGE and information_schema.MEMORY_USAGE_OPS_HISTORY to observe memory usage.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 13, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • tiancaiamao

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 13, 2022
@wshwsh12 wshwsh12 marked this pull request as ready for review October 14, 2022 05:28
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 14, 2022
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 22, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 24, 2022
@wshwsh12 wshwsh12 mentioned this pull request Oct 24, 2022
9 tasks
sqlInfo.SetString(fmt.Sprintf("%.256v", sqlInfo.GetString()), mysql.DefaultCollationName) // Truncated

m.infos = append(m.infos, op)
if len(m.infos) > 50 {
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not have an eviction strategy for now.
Maybe we can define m.infos = make([]*memoryOps, 50, 50) directly. Every time we write the new record in m.infos[offset]. When querying, output [m.infos:length) + [0,m.infos].

QueryForceDisk = atomicutil.NewInt64(0)
TriggerMemoryLimitGC = atomicutil.NewBool(false)
MemoryLimitGCLast = atomicutil.NewTime(time.Time{})
MemoryLimitGCToTal = atomicutil.NewInt64(0)
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
MemoryLimitGCToTal = atomicutil.NewInt64(0)
MemoryLimitGCTotal = atomicutil.NewInt64(0)
Write

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 25, 2022
@wshwsh12 wshwsh12 requested a review from XuHuaiyu October 25, 2022 06:45
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 25, 2022
@@ -2398,6 +2409,67 @@ func (e *memtableRetriever) setDataForClusterTrxSummary(ctx sessionctx.Context)
return nil
}

func (e *memtableRetriever) setDataForMemoryUsage(ctx sessionctx.Context) error {
r := &runtime.MemStats{}
runtime.ReadMemStats(r)
Copy link
Contributor

Choose a reason for hiding this comment

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

https://cs.opensource.google/go/go/+/refs/tags/go1.19.2:src/runtime/mstats.go;l=355;drc=7c404d59db3591a7c5854b38dc0f05fcb7ac0cff

Although we have to use it, I'd like to point out that ReadMemStats is not a free-lunch, it calls "stop the world" ...

Comment on lines 180 to 188
for i := m.offsets; i < len(m.infos); i++ {
if m.infos[i].killTime.Equal(zeroTime) {
continue
}
getRowFromInfo(m.infos[i])
}
for i := 0; i < m.offsets; i++ {
getRowFromInfo(m.infos[i])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Iterate the queue backward to the first element?

for i :=0; i<50; i++ {
   pos := [m.offsets + 50 - i] % 50
   info := m.infos[pos]
   if info.killTime.Equal(zeroTime) {
         break
   } 
   getRowFromInfo(info)
   ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

s/50/len(m.infos)

@@ -58,6 +62,8 @@ var memTableToClusterTables = map[string]string{
TableTiDBTrx: ClusterTableTiDBTrx,
TableDeadlocks: ClusterTableDeadlocks,
TableTrxSummary: ClusterTableTrxSummary,
TableMemoryUsage: ClusterTableMemoryUsage,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test to cover the basic
"select * from MEMORY_USAGE" or from TableMemoryUsageOpsHistory?

ClusterTableMemoryXXX might be harder, but I think we can cover the table with non-cluster-perfix

@wshwsh12 wshwsh12 requested a review from tiancaiamao October 27, 2022 14:12
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 28, 2022
@wshwsh12
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 7f50d50

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 28, 2022
@ti-chi-bot ti-chi-bot merged commit 40f059a into pingcap:master Oct 28, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Oct 28, 2022

TiDB MergeCI notify

✅ Well Done! New fixed [2] after this pr merged.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test 🔴 1 min 28 sec Existing failure
idc-jenkins-ci-tidb/integration-common-test ✅ all 17 tests passed 12 min Fixed
idc-jenkins-ci-tidb/sqllogic-test-2 ✅ all 28 tests passed 5 min 19 sec Fixed
idc-jenkins-ci/integration-cdc-test 🟢 all 38 tests passed 23 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 10 min Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 7 min 47 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 4 min 27 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 16 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 2 min 57 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants