Skip to content

Commit

Permalink
Added throttle on s3 grab concurrency
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Moore <[email protected]>
  • Loading branch information
jimmyaxod committed Nov 26, 2024
1 parent e8c3f61 commit d2ccc0b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/storage/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
)

var syncConcurrency = map[int]int{storage.BlockTypeAny: 10}
var syncGrabConcurrency = 100

type Device struct {
Provider storage.Provider
Expand Down Expand Up @@ -376,9 +377,12 @@ func NewDeviceWithLoggingMetrics(ds *config.DeviceSchema, log types.Logger, met

var wg sync.WaitGroup

concurrency := make(chan bool, syncGrabConcurrency)

// Pull these blocks in parallel
for _, as := range startConfig.AlternateSources {
wg.Add(1)
concurrency <- true
go func(a packets.AlternateSource) {
buffer := make([]byte, a.Length)
n, err := s3dest.ReadAt(buffer, a.Offset)
Expand All @@ -396,6 +400,7 @@ func NewDeviceWithLoggingMetrics(ds *config.DeviceSchema, log types.Logger, met
if err != nil || n != int(a.Length) {
panic(fmt.Sprintf("sync.start unable to write data to device from S3. %v", err))
}
<-concurrency
wg.Done()
}(as)
}
Expand Down

0 comments on commit d2ccc0b

Please sign in to comment.