Skip to content

Commit

Permalink
add keepalive settings to grpc server (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim-paskal authored Jun 23, 2021
1 parent 595c146 commit 0698dcf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ testChart:
helm template ./chart/envoy-control-plane | kubectl apply --dry-run=client --validate -f -
build:
docker build . -t paskalmaksim/envoy-control-plane:dev
build-envoy:
docker-compose build envoy-test1
buildEnvoy:
docker build ./envoy -t paskalmaksim/envoy-docker-image:dev
build-cli:
Expand Down
16 changes: 15 additions & 1 deletion cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ import (
logrushooksentry "github.com/maksim-paskal/logrus-hook-sentry"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"gopkg.in/yaml.v3"
v1 "k8s.io/api/core/v1"
)

var gitVersion = "dev"

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

Expand Down Expand Up @@ -176,7 +180,17 @@ func main() {

ctx := context.Background()
grpcOptions := []grpc.ServerOption{}
grpcOptions = append(grpcOptions, grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams))
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...)

defer grpcServer.GracefulStop()
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
volumes:
- .:/app
environment:
#- GODEBUG=http2debug=2
- MY_POD_NAMESPACE=default
ports:
- 18081:18081
Expand Down

0 comments on commit 0698dcf

Please sign in to comment.