Skip to content

Commit 027b9e6

Browse files
rpc: configure DPRC conn pool with idle timeout
DPRC pool holds a set of DRPC connections to a peer node. Until now, pool was not configired with any connection timeout under the assumption that cancellnig a stream would also free its underlying connection. However, our benchmarks where QPS fluctuates over the course of a run relevealed that streams are continously opened and closed. Because each stream in the pool corresponds to its own TCP connection (unlike gRPC, which multiplexes streams over a single connection), this constant opening and closing of a connection is undesireable. To address this, the PR adds a connection expiration mechanism so that idle connections are closed independently of the streams. Fixes: #140670 Epic: CRDB-48929 Release note: none
1 parent 4c54117 commit 027b9e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/rpc/drpc.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto/tls"
1111
"math"
1212
"net"
13+
"time"
1314

1415
"github.com/cockroachdb/cockroach/pkg/util/log"
1516
"github.com/cockroachdb/errors"
@@ -28,6 +29,9 @@ import (
2829
// have the DRPC server enabled.
2930
var ErrDRPCDisabled = errors.New("DRPC is not enabled")
3031

32+
// Default idle connection timeout for DRPC connections in the pool.
33+
var defaultDRPCConnIdleTimeout = 5 * time.Minute
34+
3135
type drpcServerI interface {
3236
Serve(ctx context.Context, lis net.Listener) error
3337
}
@@ -93,7 +97,9 @@ func newDRPCServer(_ context.Context, rpcCtx *Context) (*DRPCServer, error) {
9397
func dialDRPC(rpcCtx *Context) func(ctx context.Context, target string) (drpcpool.Conn, error) {
9498
return func(ctx context.Context, target string) (drpcpool.Conn, error) {
9599
// TODO(server): could use connection class instead of empty key here.
96-
pool := drpcpool.New[struct{}, drpcpool.Conn](drpcpool.Options{})
100+
pool := drpcpool.New[struct{}, drpcpool.Conn](drpcpool.Options{
101+
Expiration: defaultDRPCConnIdleTimeout,
102+
})
97103
pooledConn := pool.Get(ctx /* unused */, struct{}{}, func(ctx context.Context,
98104
_ struct{}) (drpcpool.Conn, error) {
99105

0 commit comments

Comments
 (0)