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

tidb oom when insert 4m big value #36503

Closed
Lily2025 opened this issue Jul 25, 2022 · 8 comments
Closed

tidb oom when insert 4m big value #36503

Lily2025 opened this issue Jul 25, 2022 · 8 comments
Assignees
Labels
epic/plan-cache sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@Lily2025
Copy link

Lily2025 commented Jul 25, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tidb:8core 32GB
insert 4m big value with 256 Concurrency
code:
https://github.com/pingcap/endless/blob/master/pkg/workload/append.go

2. What did you expect to see? (Required)

tidb shoud not oom

3. What did you see instead (Required)

After running for a while, one tidb oom
SgMUMT1bv3
w := workload.AppendWorkload{
DB: db,
Concurrency: 256,
Tables: 256,
PadLength: 4000000,
}
Try(w.Prepare())
w.Run(gctx)

4. What is your TiDB version? (Required)

./tidb-server -V
Release Version: v6.2.0-alpha
Edition: Community
Git Commit Hash: 28a8ffc
Git Branch: heads/refs/tags/v6.2.0-alpha
UTC Build Time: 2022-07-23 11:07:09
GoVersion: go1.18.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore

@Lily2025 Lily2025 added the type/bug The issue is confirmed as a bug. label Jul 25, 2022
@Lily2025
Copy link
Author

/type bug
/severity major
/assign XuHuaiyu

@ti-chi-bot ti-chi-bot added severity/major may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 may-affects-6.2 labels Jul 25, 2022
@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Jul 25, 2022

reproducible script:
main.txt

heap profile:
heap_tidb_172.16.4.7_4040_1658737560.txt

@XuHuaiyu
Copy link
Contributor

  1. The dashboard shows that inuse space is about 7GB~13GB.

截屏2022-07-25 下午4 39 23

  1. We can only see ~5.6GB inuse memory space from the profile

截屏2022-07-25 下午4 37 59

  1. We can see from the alloc_space that GetTextToLog allocates too many small objects, which are GCed thus we can not see from the profile inuse space.

截屏2022-07-25 下午4 42 55

@tiancaiamao
Copy link
Contributor

After analyzing the heap profile, I find the memory usage is expected.

Maybe you can try the non-prepared SQL, it might reduce the memory by more than a half.

@tiancaiamao
Copy link
Contributor

Or a tiny optimization could be, after handleStmtExecute, we clean up the params for the prepared statment. @qw4990

@qw4990
Copy link
Contributor

qw4990 commented Aug 18, 2022

Or a tiny optimization could be, after handleStmtExecute, we clean up the params for the prepared statment. @qw4990

OK, I'll take a look at this in Sprint10. It should be an enhancement instead of a bug.

@qw4990 qw4990 self-assigned this Aug 18, 2022
@qw4990 qw4990 added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner and removed type/bug The issue is confirmed as a bug. severity/major may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. labels Aug 18, 2022
@tiancaiamao
Copy link
Contributor

After #33651, the reproduce script fail to run.

@tiancaiamao
Copy link
Contributor

I test this again with tiup nightly...
Since the nightly use general plan cache, the performance should be better
(nightly, not master because master disable it #46504)

I have some new findings.
The actually inuse memory is 6G (<7G) stably, and the RSS is 27G ...
'reserved by Go' takes too much memory

And after I run "set @@global.tidb_enable_gogc_tuner = 0", the memory usage decrease a lot!
From 29G -> 15G, as you see from the below picture.

image

And the 'reserved-by-go' nearly gone.

So this OOM issue is by the gctunner feature, and we can workaround it, close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic/plan-cache sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

6 participants