Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 633d9ea

Browse files
authored
Set a minimum size for reqsChan in batcher (#221)
1 parent 6f7321c commit 633d9ea

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

metrics_batcher.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import (
2424
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
2525
)
2626

27-
const minNumWorkers = 1
27+
const (
28+
minNumWorkers = 1
29+
minReqsChanSize = 5
30+
)
2831

2932
type metricsBatcher struct {
3033
projectName string
@@ -46,7 +49,11 @@ func newMetricsBatcher(ctx context.Context, projectID string, numWorkers int, mc
4649
numWorkers = minNumWorkers
4750
}
4851
workers := make([]*worker, 0, numWorkers)
49-
reqsChan := make(chan *monitoringpb.CreateTimeSeriesRequest, 3*numWorkers)
52+
reqsChanSize := numWorkers
53+
if reqsChanSize < minReqsChanSize {
54+
reqsChanSize = minReqsChanSize
55+
}
56+
reqsChan := make(chan *monitoringpb.CreateTimeSeriesRequest, reqsChanSize)
5057
respsChan := make(chan *response, numWorkers)
5158
var wg sync.WaitGroup
5259
wg.Add(numWorkers)

0 commit comments

Comments
 (0)