Skip to content

Commit

Permalink
set grpcOptions to reduce envoy disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Jan 5, 2022
1 parent 2d04aa8 commit 23ee20d
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/envoy/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"strconv"
"strings"
"time"

clusterservice "github.com/envoyproxy/go-control-plane/envoy/service/cluster/v3"
discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand All @@ -22,10 +23,18 @@ import (
"github.com/in4it/roxprox/proto/notification"
"github.com/juju/loggo"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)

var logger = loggo.GetLogger("xds")

const (
grpcKeepaliveTime = 30 * time.Second
grpcKeepaliveTimeout = 5 * time.Second
grpcKeepaliveMinTime = 30 * time.Second
grpcMaxConcurrentStreams = 1000000
)

type XDS struct {
s storage.Storage
objects []pkgApi.Object
Expand All @@ -48,7 +57,23 @@ func NewXDS(s storage.Storage, acmeContact, port string) *XDS {

server := xds.NewServer(context.Background(), x.workQueue.InitCache(), x.workQueue.InitCallback())
if port != "" {
grpcServer := grpc.NewServer()
// gRPC golang library sets a very small upper bound for the number gRPC/h2
// streams over a single TCP connection. If a proxy multiplexes requests over
// a single connection to the management server, then it might lead to
// availability problems. Keepalive timeouts based on connection_keepalive parameter https://www.envoyproxy.io/docs/envoy/latest/configuration/overview/examples#dynamic
var grpcOptions []grpc.ServerOption
grpcOptions = append(grpcOptions,
grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams),
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: grpcKeepaliveTime,
Timeout: grpcKeepaliveTimeout,
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: grpcKeepaliveMinTime,
PermitWithoutStream: true,
}),
)
grpcServer := grpc.NewServer(grpcOptions...)
lis, _ := net.Listen("tcp", ":"+port)

discovery.RegisterAggregatedDiscoveryServiceServer(grpcServer, server)
Expand Down

0 comments on commit 23ee20d

Please sign in to comment.