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

*: use iterator in show ddl jobs to avoid oom when there is too many history ddl jobs. #12472

Merged
merged 16 commits into from
Feb 10, 2020

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Sep 29, 2019

What problem does this PR solve?

  • Fix admin show ddl jobs 100000 oom when too many history DDL jobs.

Test

Assume that we have 30,000 history ddl jobs.

Before this PR

image

This PR:

image

What is changed and how it works?

Use iterator to fetch history DDL jobs.

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix the issue that admin show ddl jobs 100000 oom when there is too many history DDL jobs.

@crazycs520 crazycs520 added the type/enhancement The issue or PR belongs to an enhancement. label Sep 29, 2019
@crazycs520 crazycs520 changed the title Show large ddl *: use iterator in show ddl jobs to avoid oom when there is too many history ddl jobs. Sep 29, 2019
@codecov
Copy link

codecov bot commented Sep 29, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@40cfd5b). Click here to learn what that means.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #12472   +/-   ##
===========================================
  Coverage          ?   79.8008%           
===========================================
  Files             ?        460           
  Lines             ?     102153           
  Branches          ?          0           
===========================================
  Hits              ?      81519           
  Misses            ?      14746           
  Partials          ?       5888

@sre-bot
Copy link
Contributor

sre-bot commented Jan 5, 2020

@crazycs520, please update your pull request.

structure/hash.go Outdated Show resolved Hide resolved
meta/meta.go Outdated Show resolved Hide resolved
meta/meta.go Outdated Show resolved Hide resolved
crazycs520 and others added 4 commits January 14, 2020 20:02
@reafans
Copy link
Contributor

reafans commented Jan 17, 2020

lgtm

@sre-bot
Copy link
Contributor

sre-bot commented Jan 21, 2020

@crazycs520, please update your pull request.

1 similar comment
@sre-bot
Copy link
Contributor

sre-bot commented Jan 28, 2020

@crazycs520, please update your pull request.

if len(jobs) < num {
jobs = make([]*model.Job, 0, num)
}
jobs = jobs[:0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, If the variable jobs always been used, then it will cause the memory leaks.

The variable of jobs won't be always used, so it won't have the memory leaks problem.

m := meta.NewMeta(txn)
historyJobIter, err := m.GetLastHistoryDDLJobsIterator()

//historyJobs, err := admin.GetHistoryDDLJobs(txn, int(e.jobNumber))
Copy link
Contributor

Choose a reason for hiding this comment

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

one question: I find the jobs returned is still the same, same slice size...
So the key to avoid oom are: 1.avoid sort & 2. kv iterator eliminate memory allocation?

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, it mostly is eliminate the large memory allocation.

For example, before this PR, If we need to get 1 million history DDL jobs, we need to allocate a slice with 1 million size.

Copy link
Contributor

Choose a reason for hiding this comment

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

got

Signed-off-by: crazycs <crazycs520@gmail.com>
Copy link
Contributor

@Deardrops Deardrops 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

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@crazycs520
Copy link
Contributor Author

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 10, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Feb 10, 2020

/run-all-tests

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. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants