From 4c15a47fd809ed5f144d206d0ddec73c6a04b6e4 Mon Sep 17 00:00:00 2001 From: Mike Gibson Date: Thu, 13 Jun 2024 15:54:39 +0100 Subject: [PATCH 1/2] Processor optimisation - reduce concurrency --- internal/processor/processor.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/processor/processor.go b/internal/processor/processor.go index e7452984..d20c66a5 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -116,10 +116,16 @@ func (c processor) Process(ctx context.Context, params MessageParams) error { tcs = append(tcs, tc) } var wg sync.WaitGroup + sem := semaphore.NewWeighted(5) for _, torrent := range searchResult.Torrents { wg.Add(1) go func() { defer wg.Done() + if semErr := sem.Acquire(ctx, 1); semErr != nil { + addFailedHash(torrent.InfoHash, semErr) + return + } + defer sem.Release(1) thisDeleteIds := make(map[string]struct{}, len(torrent.Contents)) foundMatch := false for _, tc := range torrent.Contents { From f877b1e80a76cf24ab7c875056203011c2ee7ac3 Mon Sep 17 00:00:00 2001 From: Mike Gibson Date: Thu, 13 Jun 2024 16:00:39 +0100 Subject: [PATCH 2/2] Processor optimisation - reduce concurrency --- internal/processor/processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/processor/processor.go b/internal/processor/processor.go index d20c66a5..a432f9a5 100644 --- a/internal/processor/processor.go +++ b/internal/processor/processor.go @@ -116,7 +116,7 @@ func (c processor) Process(ctx context.Context, params MessageParams) error { tcs = append(tcs, tc) } var wg sync.WaitGroup - sem := semaphore.NewWeighted(5) + sem := semaphore.NewWeighted(3) for _, torrent := range searchResult.Torrents { wg.Add(1) go func() {