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. DetailsReviewer 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.
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
|
|
||
| // 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.
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.
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.
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) |
|
/merge |
|
This pull request has been accepted and is ready to merge. DetailsCommit 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. DetailsInstructions 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.