Skip to content

Commit 8d90332

Browse files
authored
Throttler: Use cached client for CheckThrottler tabletmanager RPC (#14979)
Signed-off-by: Matt Lord <mattalord@gmail.com>
1 parent a207a69 commit 8d90332

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

go/flags/endtoend/vtbackup.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Flags:
206206
--stderrthreshold severityFlag logs at or above this threshold go to stderr (default 1)
207207
--tablet_manager_grpc_ca string the server ca to use to validate servers when connecting
208208
--tablet_manager_grpc_cert string the cert to use to connect
209-
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App}) (default 8)
209+
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler) (default 8)
210210
--tablet_manager_grpc_connpool_size int number of tablets to keep tmclient connections open to (default 100)
211211
--tablet_manager_grpc_crl string the server crl to use to validate server certificates when connecting
212212
--tablet_manager_grpc_key string the key to use to connect

go/flags/endtoend/vtcombo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Flags:
343343
--tablet_hostname string if not empty, this hostname will be assumed instead of trying to resolve it
344344
--tablet_manager_grpc_ca string the server ca to use to validate servers when connecting
345345
--tablet_manager_grpc_cert string the cert to use to connect
346-
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App}) (default 8)
346+
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler) (default 8)
347347
--tablet_manager_grpc_connpool_size int number of tablets to keep tmclient connections open to (default 100)
348348
--tablet_manager_grpc_crl string the server crl to use to validate server certificates when connecting
349349
--tablet_manager_grpc_key string the key to use to connect

go/flags/endtoend/vtctld.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Flags:
139139
--tablet_health_keep_alive duration close streaming tablet health connection if there are no requests for this long (default 5m0s)
140140
--tablet_manager_grpc_ca string the server ca to use to validate servers when connecting
141141
--tablet_manager_grpc_cert string the cert to use to connect
142-
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App}) (default 8)
142+
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler) (default 8)
143143
--tablet_manager_grpc_connpool_size int number of tablets to keep tmclient connections open to (default 100)
144144
--tablet_manager_grpc_crl string the server crl to use to validate server certificates when connecting
145145
--tablet_manager_grpc_key string the key to use to connect

go/flags/endtoend/vtorc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Flags:
8181
--table-refresh-interval int interval in milliseconds to refresh tables in status page with refreshRequired class
8282
--tablet_manager_grpc_ca string the server ca to use to validate servers when connecting
8383
--tablet_manager_grpc_cert string the cert to use to connect
84-
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App}) (default 8)
84+
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler) (default 8)
8585
--tablet_manager_grpc_connpool_size int number of tablets to keep tmclient connections open to (default 100)
8686
--tablet_manager_grpc_crl string the server crl to use to validate server certificates when connecting
8787
--tablet_manager_grpc_key string the key to use to connect

go/flags/endtoend/vttablet.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ Flags:
350350
--tablet_hostname string if not empty, this hostname will be assumed instead of trying to resolve it
351351
--tablet_manager_grpc_ca string the server ca to use to validate servers when connecting
352352
--tablet_manager_grpc_cert string the cert to use to connect
353-
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App}) (default 8)
353+
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler) (default 8)
354354
--tablet_manager_grpc_connpool_size int number of tablets to keep tmclient connections open to (default 100)
355355
--tablet_manager_grpc_crl string the server crl to use to validate server certificates when connecting
356356
--tablet_manager_grpc_key string the key to use to connect

go/flags/endtoend/vttestserver.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Flags:
119119
--tablet_hostname string The hostname to use for the tablet otherwise it will be derived from OS' hostname (default "localhost")
120120
--tablet_manager_grpc_ca string the server ca to use to validate servers when connecting
121121
--tablet_manager_grpc_cert string the cert to use to connect
122-
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App}) (default 8)
122+
--tablet_manager_grpc_concurrency int concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler) (default 8)
123123
--tablet_manager_grpc_connpool_size int number of tablets to keep tmclient connections open to (default 100)
124124
--tablet_manager_grpc_crl string the server crl to use to validate server certificates when connecting
125125
--tablet_manager_grpc_key string the key to use to connect

go/vt/vttablet/grpctmclient/client.go

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
)
5656

5757
func registerFlags(fs *pflag.FlagSet) {
58-
fs.IntVar(&concurrency, "tablet_manager_grpc_concurrency", concurrency, "concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,AllPrivs,App})")
58+
fs.IntVar(&concurrency, "tablet_manager_grpc_concurrency", concurrency, "concurrency to use to talk to a vttablet server for performance-sensitive RPCs (like ExecuteFetchAs{Dba,App} and CheckThrottler)")
5959
fs.StringVar(&cert, "tablet_manager_grpc_cert", cert, "the cert to use to connect")
6060
fs.StringVar(&key, "tablet_manager_grpc_key", key, "the key to use to connect")
6161
fs.StringVar(&ca, "tablet_manager_grpc_ca", ca, "the server ca to use to validate servers when connecting")
@@ -94,10 +94,9 @@ type tmc struct {
9494

9595
// grpcClient implements both dialer and poolDialer.
9696
type grpcClient struct {
97-
// This cache of connections is to maximize QPS for ExecuteFetch.
98-
// Note we'll keep the clients open and close them upon Close() only.
99-
// But that's OK because usually the tasks that use them are
100-
// one-purpose only.
97+
// This cache of connections is to maximize QPS for ExecuteFetchAs{Dba,App} and
98+
// CheckThrottler. Note we'll keep the clients open and close them upon Close() only.
99+
// But that's OK because usually the tasks that use them are one-purpose only.
101100
// The map is protected by the mutex.
102101
mu sync.Mutex
103102
rpcClientMap map[string]chan *tmc
@@ -115,16 +114,17 @@ type poolDialer interface {
115114
// Client implements tmclient.TabletManagerClient.
116115
//
117116
// Connections are produced by the dialer implementation, which is either the
118-
// grpcClient implementation, which reuses connections only for ExecuteFetch and
119-
// otherwise makes single-purpose connections that are closed after use.
117+
// grpcClient implementation, which reuses connections only for ExecuteFetchAs{Dba,App}
118+
// and CheckThrottler, otherwise making single-purpose connections that are closed
119+
// after use.
120120
//
121121
// In order to more efficiently use the underlying tcp connections, you can
122122
// instead use the cachedConnDialer implementation by specifying
123123
//
124-
// -tablet_manager_protocol "grpc-cached"
124+
// --tablet_manager_protocol "grpc-cached"
125125
//
126-
// The cachedConnDialer keeps connections to up to -tablet_manager_grpc_connpool_size distinct
127-
// tablets open at any given time, for faster per-RPC call time, and less
126+
// The cachedConnDialer keeps connections to up to --tablet_manager_grpc_connpool_size
127+
// distinct tablets open at any given time, for faster per-RPC call time, and less
128128
// connection churn.
129129
type Client struct {
130130
dialer dialer
@@ -1002,12 +1002,29 @@ func (client *Client) Backup(ctx context.Context, tablet *topodatapb.Tablet, req
10021002
}
10031003

10041004
// CheckThrottler is part of the tmclient.TabletManagerClient interface.
1005+
// It always tries to use a cached client via the dialer pool as this is
1006+
// called very frequently between tablets when the throttler is enabled in
1007+
// a keyspace and the overhead of creating a new gRPC connection/channel
1008+
// and dialing the other tablet every time is not practical.
10051009
func (client *Client) CheckThrottler(ctx context.Context, tablet *topodatapb.Tablet, req *tabletmanagerdatapb.CheckThrottlerRequest) (*tabletmanagerdatapb.CheckThrottlerResponse, error) {
1006-
c, closer, err := client.dialer.dial(ctx, tablet)
1007-
if err != nil {
1008-
return nil, err
1010+
var c tabletmanagerservicepb.TabletManagerClient
1011+
var err error
1012+
if poolDialer, ok := client.dialer.(poolDialer); ok {
1013+
c, err = poolDialer.dialPool(ctx, tablet)
1014+
if err != nil {
1015+
return nil, err
1016+
}
10091017
}
1010-
defer closer.Close()
1018+
1019+
if c == nil {
1020+
var closer io.Closer
1021+
c, closer, err = client.dialer.dial(ctx, tablet)
1022+
if err != nil {
1023+
return nil, err
1024+
}
1025+
defer closer.Close()
1026+
}
1027+
10111028
response, err := c.CheckThrottler(ctx, req)
10121029
if err != nil {
10131030
return nil, err

0 commit comments

Comments
 (0)