Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(processor): Memory usage in workers #335

Merged
merged 15 commits into from
Jun 17, 2024
20 changes: 13 additions & 7 deletions pkg/processor/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
DefaultExportTimeout = 30000
DefaultMaxExportBatchSize = 512
DefaultShippingMethod = ShippingMethodAsync
DefaultNumWorkers = 1
DefaultNumWorkers = 5
)

// ShippingMethod is the method of shipping items for export.
Expand Down Expand Up @@ -77,7 +77,7 @@ type BatchItemProcessorOptions struct {
// of ShippingMethod is "async".
ShippingMethod ShippingMethod
// Workers is the number of workers to process batches.
// The default value of Workers is 1.
// The default value of Workers is 5.
Workers int
}

Expand Down Expand Up @@ -223,12 +223,18 @@ func (bvp *BatchItemProcessor[T]) Write(ctx context.Context, s []*T) error {
}

prepared := []traceableItem[T]{}

for _, i := range s[start:end] {
prepared = append(prepared, traceableItem[T]{
item: i,
errCh: make(chan error, 1),
completedCh: make(chan struct{}, 1),
})
item := traceableItem[T]{
item: i,
}

if bvp.o.ShippingMethod == ShippingMethodSync {
item.errCh = make(chan error, 1)
item.completedCh = make(chan struct{}, 1)
}

prepared = append(prepared, item)
}

for _, i := range prepared {
Expand Down
Loading