Skip to content

Commit

Permalink
parallelise requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Dec 18, 2024
1 parent 1c9c5cc commit dcf90f4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
})
}
}

Expand Down

0 comments on commit dcf90f4

Please sign in to comment.