-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
planner: LRUPlanCache memory trace #38069
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
planner/core/plan_cache_lru.go
Outdated
const emptyLRUPlanCacheSize = int64(unsafe.Sizeof(LRUPlanCache{})) | ||
|
||
// MemoryUsage return the memory usage of LRUPlanCache | ||
func (l *LRUPlanCache) MemoryUsage() (sum int64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should maintain its memory usage dynamically in l.Put
.
…tidb into planCacheValue_memTrace
…tidb into planCacheValue_memTrace
planner/core/plan_cache_utils.go
Outdated
} | ||
|
||
func (v *PlanCacheValue) varTypesUnchanged(txtVarTps []*types.FieldType) bool { | ||
return v.ParamTypes.CheckTypesCompatibility4PC(txtVarTps) | ||
} | ||
|
||
// unKnownMemoryUsage represent the memory usage of uncounted structure, maybe need implement later | ||
// 7 has no special meaning | ||
const unKnownMemoryUsage = 7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems too small. Actually, I have tested it before and got an empirical value 100KB
, you can see it in our doc https://docs.pingcap.com/tidb/dev/sql-prepared-plan-cache#memory-management-of-prepared-plan-cache
planner/core/plan_cache_lru.go
Outdated
// todo: pass label when track general plan cache memory | ||
func newTrackerForLRUPC() *memory.Tracker { | ||
m := memory.NewTracker(memory.LabelForPreparedPlanCache, -1) | ||
m.Consume(emptyLRUPlanCacheSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about ignoring this part of memory usage?
planner/core/plan_cache_lru.go
Outdated
func elementMemoryUsage(e *list.Element) (sum int64) { | ||
pVal, ok1 := e.Value.(*planCacheEntry).PlanValue.(*PlanCacheValue) | ||
pKey, ok2 := e.Value.(*planCacheEntry).PlanValue.(*planCacheKey) | ||
if !ok1 || !ok2 { | ||
return | ||
} | ||
return pKey.MemoryUsage() + pVal.MemoryUsage() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please implement this function as planCacheEntry.MemoryUsage
/run-build |
planner/core/plan_cache_lru_test.go
Outdated
v := &PlanCacheValue{Plan: p} | ||
lru.Put(k, v, pTypes) | ||
res += k.MemoryUsage() + v.MemoryUsage() | ||
fmt.Println(lru.MemoryUsage(), res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove this line.
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 0445583
|
@fzzf678: 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. |
What problem does this PR solve?
Issue Number: ref #37632
Problem Summary:
Count the memory usage of LRUPlanCache
What is changed and how it works?
Implement MemoryUsage() for
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.