Browse Source

fix too many pings (#7566)

* fix too many pings

* constants

* Update weed/pb/grpc_client_server.go

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
pull/4038/merge
Chris Lu 5 days ago
committed by GitHub
parent
commit
03ce060e85
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
  2. 14
      weed/pb/grpc_client_server.go

8
other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java

@ -22,6 +22,10 @@ public class FilerGrpcClient {
private static final SslContext sslContext; private static final SslContext sslContext;
private static final String protocol; private static final String protocol;
// gRPC keepalive settings - must be consistent with server-side settings in grpc_client_server.go
private static final long KEEP_ALIVE_TIME_SECONDS = 60L;
private static final long KEEP_ALIVE_TIMEOUT_SECONDS = 20L;
static { static {
sslContext = FilerSecurityContext.getGrpcSslContext(); sslContext = FilerSecurityContext.getGrpcSslContext();
protocol = FilerSecurityContext.isHttpSecurityEnabled() ? "https" : "http"; protocol = FilerSecurityContext.isHttpSecurityEnabled() ? "https" : "http";
@ -81,8 +85,8 @@ public class FilerGrpcClient {
.flowControlWindow(16 * 1024 * 1024) .flowControlWindow(16 * 1024 * 1024)
.initialFlowControlWindow(16 * 1024 * 1024) .initialFlowControlWindow(16 * 1024 * 1024)
.maxHeaderListSize(16 * 1024 * 1024) .maxHeaderListSize(16 * 1024 * 1024)
.keepAliveTime(30, TimeUnit.SECONDS)
.keepAliveTimeout(10, TimeUnit.SECONDS)
.keepAliveTime(KEEP_ALIVE_TIME_SECONDS, TimeUnit.SECONDS)
.keepAliveTimeout(KEEP_ALIVE_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.keepAliveWithoutCalls(true) .keepAliveWithoutCalls(true)
.withOption(io.grpc.netty.shaded.io.netty.channel.ChannelOption.SO_RCVBUF, 16 * 1024 * 1024) .withOption(io.grpc.netty.shaded.io.netty.channel.ChannelOption.SO_RCVBUF, 16 * 1024 * 1024)
.withOption(io.grpc.netty.shaded.io.netty.channel.ChannelOption.SO_SNDBUF, 16 * 1024 * 1024); .withOption(io.grpc.netty.shaded.io.netty.channel.ChannelOption.SO_SNDBUF, 16 * 1024 * 1024);

14
weed/pb/grpc_client_server.go

@ -29,6 +29,10 @@ import (
const ( const (
Max_Message_Size = 1 << 30 // 1 GB Max_Message_Size = 1 << 30 // 1 GB
// gRPC keepalive settings - must be consistent between client and server
GrpcKeepAliveTime = 60 * time.Second // ping interval when no activity
GrpcKeepAliveTimeout = 20 * time.Second // ping timeout
) )
var ( var (
@ -52,12 +56,12 @@ func NewGrpcServer(opts ...grpc.ServerOption) *grpc.Server {
var options []grpc.ServerOption var options []grpc.ServerOption
options = append(options, options = append(options,
grpc.KeepaliveParams(keepalive.ServerParameters{ grpc.KeepaliveParams(keepalive.ServerParameters{
Time: 30 * time.Second, // wait time before ping if no activity (match client)
Timeout: 20 * time.Second, // ping timeout
Time: GrpcKeepAliveTime, // server pings client if no activity for this long
Timeout: GrpcKeepAliveTimeout, // ping timeout
// MaxConnectionAge: 10 * time.Hour, // MaxConnectionAge: 10 * time.Hour,
}), }),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 30 * time.Second, // min time a client should wait before sending a ping (match client)
MinTime: GrpcKeepAliveTime, // min time a client should wait before sending a ping
PermitWithoutStream: true, PermitWithoutStream: true,
}), }),
grpc.MaxRecvMsgSize(Max_Message_Size), grpc.MaxRecvMsgSize(Max_Message_Size),
@ -89,8 +93,8 @@ func GrpcDial(ctx context.Context, address string, waitForReady bool, opts ...gr
grpc.WaitForReady(waitForReady), grpc.WaitForReady(waitForReady),
), ),
grpc.WithKeepaliveParams(keepalive.ClientParameters{ grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 30 * time.Second, // client ping server if no activity for this long
Timeout: 20 * time.Second,
Time: GrpcKeepAliveTime, // client ping server if no activity for this long
Timeout: GrpcKeepAliveTimeout, // ping timeout
PermitWithoutStream: true, PermitWithoutStream: true,
})) }))
for _, opt := range opts { for _, opt := range opts {

Loading…
Cancel
Save