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

executor: more precise memory tracking #35785

Merged
Merged
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e58abd3
precise memory tracking
mengxin9014 Jun 28, 2022
dddba4e
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Jun 28, 2022
286535a
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Jul 7, 2022
fffaa61
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Jul 7, 2022
cc00efa
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
hawkingrei Jul 13, 2022
2ebf3cd
modify according to comments
mengxin9014 Jul 15, 2022
8cf2d53
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Jul 15, 2022
cfc2fd1
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Jul 15, 2022
7e71a9a
fix some problems
mengxin9014 Jul 15, 2022
3e1139d
Merge branch 'mx/preassignForPreciseMemoryTracking' of github.com:men…
mengxin9014 Jul 15, 2022
5390571
modify according to comments
mengxin9014 Jul 15, 2022
38851b9
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Jul 27, 2022
619ef73
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Aug 9, 2022
7682a0f
memory tracking is more accurate
mengxin9014 Aug 9, 2022
a54fa93
Precise Memory Tracking
mengxin9014 Aug 9, 2022
beba27e
split pr
mengxin9014 Aug 10, 2022
ceb37e8
split pr
mengxin9014 Aug 10, 2022
2153cac
split pr
mengxin9014 Aug 10, 2022
cd21e7a
refactor
mengxin9014 Aug 10, 2022
bcc801c
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Aug 10, 2022
569e4c6
delete unuseful code
mengxin9014 Aug 10, 2022
6001cba
modify some problem
mengxin9014 Aug 10, 2022
bf8e56c
rename function
mengxin9014 Aug 10, 2022
6eb1758
move init out of loop
mengxin9014 Aug 10, 2022
d8a8711
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
mengxin9014 Aug 10, 2022
2e1663b
Merge branch 'master' into mx/preassignForPreciseMemoryTracking
ti-chi-bot Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions executor/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sync"
"sync/atomic"
"time"
"unsafe"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
Expand Down Expand Up @@ -599,10 +600,11 @@ func (w *baseHashAggWorker) getPartialResult(sc *stmtctx.StatementContext, group
if partialResults[i], ok = mapper[string(groupKey[i])]; ok {
continue
}
for _, af := range w.aggFuncs {
partialResults[i] = make([]aggfuncs.PartialResult, len(w.aggFuncs))
for j, af := range w.aggFuncs {
partialResult, memDelta := af.AllocPartialResult()
partialResults[i] = append(partialResults[i], partialResult)
allMemDelta += memDelta + 8 // the memory usage of PartialResult
partialResults[i][j] = partialResult
allMemDelta += memDelta + int64(unsafe.Sizeof(partialResult)) // the memory usage of PartialResult
}
mapper[string(groupKey[i])] = partialResults[i]
allMemDelta += int64(len(groupKey[i]))
Expand Down Expand Up @@ -654,13 +656,12 @@ func (w *HashAggFinalWorker) consumeIntermData(sctx sessionctx.Context) (err err
for reachEnd := false; !reachEnd; {
intermDataBuffer, groupKeys, reachEnd = input.getPartialResultBatch(sc, intermDataBuffer[:0], w.aggFuncs, w.maxChunkSize)
groupKeysLen := len(groupKeys)
memSize := getGroupKeyMemUsage(w.groupKeys)
w.groupKeys = w.groupKeys[:0]
w.groupKeys = make([][]byte, groupKeysLen)
for i := 0; i < groupKeysLen; i++ {
w.groupKeys = append(w.groupKeys, []byte(groupKeys[i]))
w.groupKeys[i] = []byte(groupKeys[i])
}
failpoint.Inject("ConsumeRandomPanic", nil)
w.memTracker.Consume(getGroupKeyMemUsage(w.groupKeys) - memSize)
w.memTracker.Consume(getGroupKeyMemUsage(w.groupKeys))
finalPartialResults := w.getPartialResult(sc, w.groupKeys, w.partialResultMap)
allMemDelta := int64(0)
for i, groupKey := range groupKeys {
Expand Down Expand Up @@ -695,13 +696,14 @@ func (w *HashAggFinalWorker) getFinalResult(sctx sessionctx.Context) {
return
}
execStart := time.Now()
memSize := getGroupKeyMemUsage(w.groupKeys)
w.groupKeys = w.groupKeys[:0]
w.groupKeys = make([][]byte, len(w.groupSet.StringSet))
groupKeysIndex := 0
for groupKey := range w.groupSet.StringSet {
w.groupKeys = append(w.groupKeys, []byte(groupKey))
w.groupKeys[groupKeysIndex] = []byte(groupKey)
groupKeysIndex++
Copy link
Contributor

Choose a reason for hiding this comment

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

w.groupKeys = make([][]byte, 0, len(w.groupSet.StringSet))
for xxxx {
    w.groupKeys = append(w.groupKeys, []byte(groupKey))
}

}
failpoint.Inject("ConsumeRandomPanic", nil)
w.memTracker.Consume(getGroupKeyMemUsage(w.groupKeys) - memSize)
w.memTracker.Consume(getGroupKeyMemUsage(w.groupKeys))
partialResults := w.getPartialResult(sctx.GetSessionVars().StmtCtx, w.groupKeys, w.partialResultMap)
for i := 0; i < len(w.groupSet.StringSet); i++ {
for j, af := range w.aggFuncs {
Expand Down