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

util: record more information before OOM #37987

Merged

Conversation

mengxin9014
Copy link
Contributor

@mengxin9014 mengxin9014 commented Sep 20, 2022

What problem does this PR solve?

Issue Number: close ##37409

Problem Summary:

What is changed and how it works?

record more information:

  1. topN-mem-consumer
  • current explain analyze
  • desensitized SQL text
  1. memory related variables
  • system variables
  • session variables

modify record logic:

  • we will record the information if (current_mem_usage_ratio > 70% && (current_time - last_record_time > 60s || current_mem_usage_ratio - last_record_mem_usage_ratio > 10%))

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.

record more information before OOM.

@mengxin9014 mengxin9014 requested a review from a team as a code owner September 20, 2022 08:13
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 20, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • wshwsh12

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 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 20, 2022
@mengxin9014
Copy link
Contributor Author

/cc @XuHuaiyu

@mengxin9014
Copy link
Contributor Author

/cc @wshwsh12

@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 20, 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 Sep 25, 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 Sep 26, 2022
)

func (reason AlarmReason) String() string {
return [...]string{"memory increase too fast", "memory used exceed", "no reason"}[reason]
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
return [...]string{"memory increase too fast", "memory used exceed", "no reason"}[reason]
return [...]string{"memory usage grows too fast", "memory usage exceeds alarm ratio", "no reason"}[reason]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 167 to 174
const (
// IncreaseFast is the reason that memory increasing too fast.
IncreaseFast AlarmReason = iota
// MemoryExceed is the reason that memory used exceed threshold.
MemoryExceed
// NoReason means no alarm
NoReason
)
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
const (
// IncreaseFast is the reason that memory increasing too fast.
IncreaseFast AlarmReason = iota
// MemoryExceed is the reason that memory used exceed threshold.
MemoryExceed
// NoReason means no alarm
NoReason
)
const (
// GrowTooFast is the reason that memory usage grows too fast.
GrowTooFast AlarmReason = iota
// ExceedAlarmRatio is the reason that memory usage exceeds the alarm ratio.
ExceedAlarmRatio
// NoReason means no alarm
NoReason
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

record.lastCheckTime = time.Now()
record.lastRecordMemUsed = memoryUsage
record.doRecord(memoryUsage, instanceStats.HeapAlloc, sm, reason)
record.tryRemoveNoNeedRecords()
Copy link
Contributor

Choose a reason for hiding this comment

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

tryRemoveRedundantRecords

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tryRemoveRedundantRecords

done.

Comment on lines 423 to +427
# The alarm threshold when memory usage of the tidb-server exceeds. The valid value range is greater than or equal to 0
# and less than or equal to 1. The default value is 0.8.
# and less than or equal to 1. The default value is 0.7.
# If this configuration is set to 0 or 1, it'll disable the alarm.
# <snip>
memory-usage-alarm-ratio = 0.8
memory-usage-alarm-ratio = 0.7
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this block

tk.MustQuery("select @@global.tidb_memory_usage_alarm_keep_record_num").Check(testkit.Rows("100"))
tk.MustExec("set @@global.tidb_memory_usage_alarm_keep_record_num=0")
tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_memory_usage_alarm_keep_record_num value: '0'"))
tk.MustQuery("select @@global.tidb_memory_usage_alarm_keep_record_num").Check(testkit.Rows("1"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test for the MAXVALUE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a test for the MAXVALUE

done.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 10, 2022
Copy link
Contributor

@wshwsh12 wshwsh12 left a comment

Choose a reason for hiding this comment

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

LGTM

@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 11, 2022
@XuHuaiyu
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 2618c09

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 12, 2022
@ti-chi-bot
Copy link
Member

@mengxin9014: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot merged commit d10e195 into pingcap:master Oct 12, 2022
@mengxin9014 mengxin9014 deleted the mx/recordMoreInformationBeforeOOM branch November 12, 2022 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note size/XXL Denotes a PR that changes 1000+ 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. type/enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants