diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-04-18 16:05:22 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2023-04-19 11:35:43 +0200 |
commit | 0483d95ca48b6f5ba1c9ad3b5c73b50fc2390145 (patch) | |
tree | a4e66d30859fb911b21e2b010b642c336d36f77c | |
parent | 6701eba23ad0ce4e5427e8aaff403d8697e548e4 (diff) |
Re-use document group lists
-rw-r--r-- | client/go/internal/vespa/document/dispatcher.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/client/go/internal/vespa/document/dispatcher.go b/client/go/internal/vespa/document/dispatcher.go index 96090c18685..1c950210a72 100644 --- a/client/go/internal/vespa/document/dispatcher.go +++ b/client/go/internal/vespa/document/dispatcher.go @@ -29,6 +29,7 @@ type Dispatcher struct { output io.Writer verbose bool + listPool sync.Pool mu sync.RWMutex workerWg sync.WaitGroup resultWg sync.WaitGroup @@ -46,11 +47,11 @@ type documentGroup struct { mu sync.Mutex } -func (g *documentGroup) add(op documentOp, first bool) { +func (g *documentGroup) add(op documentOp, first bool, listPool *sync.Pool) { g.mu.Lock() defer g.mu.Unlock() if g.ops == nil { - g.ops = list.New() + g.ops = listPool.Get().(*list.List) } if first { g.ops.PushFront(op) @@ -83,6 +84,10 @@ func (d *Dispatcher) sendDocumentIn(group *documentGroup) { result := d.feeder.Send(op.document) d.results <- result d.releaseSlot() + if group.ops.Front() == nil { // Empty list, release it back to the pool + d.listPool.Put(group.ops) + group.ops = nil + } group.mu.Unlock() if d.shouldRetry(op, result) { d.enqueue(op) @@ -134,6 +139,7 @@ func (d *Dispatcher) start() { if d.started { return } + d.listPool.New = func() any { return list.New() } d.ready = make(chan Id, 4096) d.results = make(chan Result, 4096) d.msgs = make(chan string, 4096) @@ -169,7 +175,7 @@ func (d *Dispatcher) enqueue(op documentOp) error { d.inflight[key] = group } d.mu.Unlock() - group.add(op, op.attempts > 0) + group.add(op, op.attempts > 0, &d.listPool) d.enqueueWithSlot(op.document.Id) return nil } |