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 a background region cache GC goroutine #664

Merged
merged 2 commits into from
Jan 11, 2023

Conversation

sticnarf
Copy link
Collaborator

Refers to pingcap/tidb#40461.

#566 can solve high CPU cost problems like #532. But in some cases, there will still be memory leaks when some of the stale regions are never touched again.

This PR adds a background goroutine to iterate over the cache to clean up stale region info. We don't want this goroutine to affect performance, so it runs at low frequency and each round is very fast.

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Copy link
Contributor

@ekexium ekexium left a comment

Choose a reason for hiding this comment

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

LGTM. Have we met such cases?

@sticnarf
Copy link
Collaborator Author

LGTM. Have we met such cases?

Probably. Some customer finds memory leak but the version they use does not include #566 yet.

In their case, they drop day -14 to day -7 tables every week. The regions of the removed tables may be merged into the day -6 table. However, it's possible that the day -6 table will not be touched at all.

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

LGTM

@cfzjywxk
Copy link
Contributor

/cc @jackysp

@cfzjywxk cfzjywxk merged commit a2964b7 into tikv:master Jan 11, 2023
sticnarf added a commit to sticnarf/client-go that referenced this pull request Jan 16, 2023
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
sticnarf added a commit that referenced this pull request Jan 16, 2023
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
sticnarf added a commit to sticnarf/client-go that referenced this pull request Jan 31, 2023
* Add a background region cache GC goroutine

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* Change interval to 1s and regionPerRound to 50

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
sticnarf added a commit to sticnarf/client-go that referenced this pull request Jan 31, 2023
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
disksing pushed a commit that referenced this pull request Jan 31, 2023
* RuntimeStat: Clone `SnapshotRuntimeStats` Completely (#641)

* add more info for cloning SnapshotRuntimeStats

Signed-off-by: TonsnakeLin <lpbgytong@163.com>

* add more info for cloning SnapshotRuntimeStats

Signed-off-by: TonsnakeLin <lpbgytong@163.com>

* shallow copy SnapshotRuntimeStats

Signed-off-by: TonsnakeLin <lpbgytong@163.com>

Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Co-authored-by: Yilin Chen <sticnarf@gmail.com>

* fix data race in the LockKeys (#655)

Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>

* Add a background region cache GC goroutine (#664)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* Rewind after cacheGC reaches the end (#678)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

---------

Signed-off-by: TonsnakeLin <lpbgytong@163.com>
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Co-authored-by: TonsnakeLin <87681388+TonsnakeLin@users.noreply.github.com>
Co-authored-by: Weizhen Wang <wangweizhen@pingcap.com>
disksing pushed a commit that referenced this pull request Jan 31, 2023
* Add a background region cache GC goroutine (#664)

* Add a background region cache GC goroutine

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* Change interval to 1s and regionPerRound to 50

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

* Rewind after cacheGC reaches the end (#678)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

---------

Signed-off-by: Yilin Chen <sticnarf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants