From c8097357850b1611da1f8ac5c09c024690d4b350 Mon Sep 17 00:00:00 2001 From: zyguan Date: Thu, 16 Jan 2025 02:14:53 +0000 Subject: [PATCH] txnkv: optimize batch-get by reducing overhead of backoffer Signed-off-by: zyguan --- txnkv/txnsnapshot/snapshot.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/txnkv/txnsnapshot/snapshot.go b/txnkv/txnsnapshot/snapshot.go index 746c51da3..831c97fe8 100644 --- a/txnkv/txnsnapshot/snapshot.go +++ b/txnkv/txnsnapshot/snapshot.go @@ -360,13 +360,19 @@ func (s *KVSnapshot) batchGetKeysByRegions(bo *retry.Backoffer, keys [][]byte, r if len(batches) == 1 { return s.batchGetSingleRegion(bo, batches[0], readTier, collectF) } - ch := make(chan error) - for _, batch1 := range batches { + ch := make(chan error, len(batches)) + bo, cancel := bo.Fork() + defer cancel() + for i, batch1 := range batches { + var backoffer *retry.Backoffer + if i == 0 { + backoffer = bo + } else { + backoffer = bo.Clone() + } batch := batch1 go func() { growStackForBatchGetWorker() - backoffer, cancel := bo.Fork() - defer cancel() ch <- s.batchGetSingleRegion(backoffer, batch, readTier, collectF) }() }