From dcf90f4dafc6f321c7215e9eef9536eea5b3b229 Mon Sep 17 00:00:00 2001 From: Cottand Date: Wed, 18 Dec 2024 20:59:56 +0000 Subject: [PATCH] parallelise requests --- handler.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index a8d0dec..39c6335 100644 --- a/handler.go +++ b/handler.go @@ -4,6 +4,7 @@ import ( "github.com/cottand/leng/internal/metric" "github.com/cottand/leng/lcache" "github.com/miekg/dns" + "golang.org/x/sync/errgroup" "net" "slices" "sync" @@ -77,12 +78,18 @@ func NewEventLoop(config *Config, blockCache *MemoryBlockCache) *EventLoop { } func (h *EventLoop) do() { + errGroup := errgroup.Group{} + // arbitrary cap to limit allocation spikes + errGroup.SetLimit(100) for { data, ok := <-h.requestChannel if !ok { break } - h.doRequest(data.Net, data.w, data.req) + errGroup.Go(func() error { + h.doRequest(data.Net, data.w, data.req) + return nil + }) } }