Skip to content

Commit 6361a63

Browse files
authored
ROX-20122: set gRPC max concurrent streams to 100 (#1287)
1 parent c017a55 commit 6361a63

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

api/grpc/grpc.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
1414
"github.com/grpc-ecosystem/grpc-gateway/runtime"
1515
log "github.com/sirupsen/logrus"
16+
"github.com/stackrox/scanner/pkg/env"
1617
"github.com/stackrox/scanner/pkg/mtls"
1718
"google.golang.org/grpc"
1819
"google.golang.org/grpc/credentials/insecure"
@@ -26,6 +27,14 @@ func init() {
2627
grpcprometheus.EnableHandlingTimeHistogram()
2728
}
2829

30+
func maxGrpcConcurrentStreams() uint32 {
31+
if env.MaxGrpcConcurrentStreams.Int() <= 0 {
32+
return env.DefaultMaxGrpcConcurrentStreams
33+
}
34+
35+
return uint32(env.MaxGrpcConcurrentStreams.Int())
36+
}
37+
2938
// NewAPI creates a new gRPC API instantiation
3039
func NewAPI(opts ...ConfigOpts) API {
3140
var config Config
@@ -60,7 +69,10 @@ func (a *apiImpl) connectToLocalEndpoint() (*grpc.ClientConn, error) {
6069
}
6170

6271
func (a *apiImpl) Start() {
63-
grpcServer := grpc.NewServer(grpc.ChainUnaryInterceptor(a.config.UnaryInterceptors...))
72+
grpcServer := grpc.NewServer(
73+
grpc.ChainUnaryInterceptor(a.config.UnaryInterceptors...),
74+
grpc.MaxConcurrentStreams(maxGrpcConcurrentStreams()),
75+
)
6476
for _, serv := range a.apiServices {
6577
serv.RegisterServiceServer(grpcServer)
6678
}

pkg/env/list.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package env
22

33
import "time"
44

5+
const (
6+
// DefaultMaxGrpcConcurrentStreams is the minimum value for concurrent streams recommended by the HTTP/2 spec
7+
DefaultMaxGrpcConcurrentStreams = 100
8+
)
9+
510
var (
611
// LanguageVulns enables language vulnerabilities.
712
LanguageVulns = RegisterBooleanSetting("ROX_LANGUAGE_VULNS", true, AllowWithoutRox())
@@ -38,4 +43,7 @@ var (
3843
// ActiveVulnMgmt is the same flag in Central that determines if active vulnerability management should be
3944
// enabled and executables should be pulled from the database
4045
ActiveVulnMgmt = RegisterBooleanSetting("ROX_ACTIVE_VULN_MGMT", false)
46+
47+
// MaxGrpcConcurrentStreams configures the maximum number of HTTP/2 streams to use with gRPC
48+
MaxGrpcConcurrentStreams = RegisterIntegerSetting("ROX_GRPC_MAX_CONCURRENT_STREAMS", DefaultMaxGrpcConcurrentStreams)
4149
)

0 commit comments

Comments
 (0)