Skip to content

Commit

Permalink
Make MaxConcurrentStreams configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbologa committed Oct 13, 2023
1 parent 88aae7d commit 1685e2d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions api/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,33 @@ import (
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
log "github.com/sirupsen/logrus"
"github.com/stackrox/scanner/pkg/env"
"github.com/stackrox/scanner/pkg/mtls"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

const (
localEndpoint = "127.0.0.1:8444"
localEndpoint = "127.0.0.1:8444"
defaultGrpcMaxConcurrentStreams = 100 // HTTP/2 spec recommendation for minimum value
)

func init() {
grpcprometheus.EnableHandlingTimeHistogram()
}

var (
maxGrpcConcurrentStreamsSetting = env.RegisterIntegerSetting("ROX_GRPC_MAX_CONCURRENT_STREAMS", defaultGrpcMaxConcurrentStreams)
)

func maxGrpcConcurrentStreams() uint32 {
if maxGrpcConcurrentStreamsSetting.Int() < 0 {
return defaultGrpcMaxConcurrentStreams
}

return uint32(maxGrpcConcurrentStreamsSetting.Int())
}

// NewAPI creates a new gRPC API instantiation
func NewAPI(opts ...ConfigOpts) API {
var config Config
Expand Down Expand Up @@ -62,7 +76,7 @@ func (a *apiImpl) connectToLocalEndpoint() (*grpc.ClientConn, error) {
func (a *apiImpl) Start() {
grpcServer := grpc.NewServer(
grpc.ChainUnaryInterceptor(a.config.UnaryInterceptors...),
grpc.MaxConcurrentStreams(100),
grpc.MaxConcurrentStreams(maxGrpcConcurrentStreams()),
)
for _, serv := range a.apiServices {
serv.RegisterServiceServer(grpcServer)
Expand Down

0 comments on commit 1685e2d

Please sign in to comment.