From 669c90463c976b90501bebc1ccdea659fb5d3cbf Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 27 May 2021 21:23:35 +0800 Subject: [PATCH] sorter: reduce memory malloc to avoid too much CPU overhead (#1854) (#1863) --- cdc/puller/sorter/heap_sorter.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdc/puller/sorter/heap_sorter.go b/cdc/puller/sorter/heap_sorter.go index a82c1cde67d..7cf99afc138 100644 --- a/cdc/puller/sorter/heap_sorter.go +++ b/cdc/puller/sorter/heap_sorter.go @@ -33,6 +33,7 @@ import ( const ( flushRateLimitPerSecond = 10 + sortHeapCapacity = 32 ) type flushTask struct { @@ -86,7 +87,7 @@ func newHeapSorter(id int, out chan *flushTask) *heapSorter { id: id, inputCh: make(chan *model.PolymorphicEvent, 1024*1024), outputCh: out, - heap: make(sortHeap, 0, 65536), + heap: make(sortHeap, 0, sortHeapCapacity), canceller: new(asyncCanceller), } } @@ -159,7 +160,7 @@ func (h *heapSorter) flush(ctx context.Context, maxResolvedTs uint64) error { return nil } oldHeap = h.heap - h.heap = make(sortHeap, 0, 65536) + h.heap = make(sortHeap, 0, sortHeapCapacity) } else { task.dealloc = func() error { task.markDeallocated()