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

Commit

Permalink
Set a minimum size for reqsChan in batcher (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Sep 16, 2019
1 parent 6f7321c commit 633d9ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions metrics_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import (
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
)

const minNumWorkers = 1
const (
minNumWorkers = 1
minReqsChanSize = 5
)

type metricsBatcher struct {
projectName string
Expand All @@ -46,7 +49,11 @@ func newMetricsBatcher(ctx context.Context, projectID string, numWorkers int, mc
numWorkers = minNumWorkers
}
workers := make([]*worker, 0, numWorkers)
reqsChan := make(chan *monitoringpb.CreateTimeSeriesRequest, 3*numWorkers)
reqsChanSize := numWorkers
if reqsChanSize < minReqsChanSize {
reqsChanSize = minReqsChanSize
}
reqsChan := make(chan *monitoringpb.CreateTimeSeriesRequest, reqsChanSize)
respsChan := make(chan *response, numWorkers)
var wg sync.WaitGroup
wg.Add(numWorkers)
Expand Down

0 comments on commit 633d9ea

Please sign in to comment.