Performance change to option enable client.QPS, client.Burst
and change default on max_requests_inflight.
This commit is contained in:
@@ -27,6 +27,8 @@ type FlagSet interface {
|
||||
BoolVar(p *bool, name string, value bool, usage string)
|
||||
UintVar(p *uint, name string, value uint, usage string)
|
||||
DurationVar(p *time.Duration, name string, value time.Duration, usage string)
|
||||
Float32Var(p *float32, name string, value float32, usage string)
|
||||
IntVar(p *int, name string, value int, usage string)
|
||||
}
|
||||
|
||||
// BindClientConfigFlags registers a standard set of CLI flags for connecting to a Kubernetes API server.
|
||||
@@ -38,6 +40,8 @@ func BindClientConfigFlags(flags FlagSet, config *Config) {
|
||||
flags.StringVar(&config.CertFile, "client_certificate", config.CertFile, "Path to a client key file for TLS.")
|
||||
flags.StringVar(&config.KeyFile, "client_key", config.KeyFile, "Path to a client key file for TLS.")
|
||||
flags.StringVar(&config.CAFile, "certificate_authority", config.CAFile, "Path to a cert. file for the certificate authority.")
|
||||
flags.Float32Var(&config.QPS, "max_outgoing_qps", config.QPS, "Maximum number of queries per second that could be issued by this client.")
|
||||
flags.IntVar(&config.Burst, "max_outgoing_burst", config.Burst, "Maximum throttled burst")
|
||||
}
|
||||
|
||||
func BindKubeletClientConfigFlags(flags FlagSet, config *KubeletConfig) {
|
||||
|
@@ -68,11 +68,31 @@ func (f *fakeFlagSet) DurationVar(p *time.Duration, name string, value time.Dura
|
||||
f.set.Insert(name)
|
||||
}
|
||||
|
||||
func (f *fakeFlagSet) Float32Var(p *float32, name string, value float32, usage string) {
|
||||
if p == nil {
|
||||
f.t.Errorf("unexpected nil pointer")
|
||||
}
|
||||
if usage == "" {
|
||||
f.t.Errorf("unexpected empty usage")
|
||||
}
|
||||
f.set.Insert(name)
|
||||
}
|
||||
|
||||
func (f *fakeFlagSet) IntVar(p *int, name string, value int, usage string) {
|
||||
if p == nil {
|
||||
f.t.Errorf("unexpected nil pointer")
|
||||
}
|
||||
if usage == "" {
|
||||
f.t.Errorf("unexpected empty usage")
|
||||
}
|
||||
f.set.Insert(name)
|
||||
}
|
||||
|
||||
func TestBindClientConfigFlags(t *testing.T) {
|
||||
flags := &fakeFlagSet{t, util.StringSet{}}
|
||||
config := &Config{}
|
||||
BindClientConfigFlags(flags, config)
|
||||
if len(flags.set) != 6 {
|
||||
if len(flags.set) != 8 {
|
||||
t.Errorf("unexpected flag set: %#v", flags)
|
||||
}
|
||||
}
|
||||
|
@@ -80,6 +80,9 @@ type Config struct {
|
||||
|
||||
// QPS indicates the maximum QPS to the master from this client. If zero, QPS is unlimited.
|
||||
QPS float32
|
||||
|
||||
// Maximum burst for throttle
|
||||
Burst int
|
||||
}
|
||||
|
||||
type KubeletConfig struct {
|
||||
@@ -181,6 +184,9 @@ func SetKubernetesDefaults(config *Config) error {
|
||||
if config.QPS == 0.0 {
|
||||
config.QPS = 5.0
|
||||
}
|
||||
if config.Burst == 0 {
|
||||
config.Burst = 10
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -201,7 +207,7 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := NewRESTClient(baseURL, config.Version, config.Codec, config.LegacyBehavior, config.QPS)
|
||||
client := NewRESTClient(baseURL, config.Version, config.Codec, config.LegacyBehavior, config.QPS, config.Burst)
|
||||
|
||||
transport, err := TransportFor(config)
|
||||
if err != nil {
|
||||
|
@@ -274,6 +274,7 @@ func TestSetKubernetesDefaults(t *testing.T) {
|
||||
Codec: latest.Codec,
|
||||
LegacyBehavior: (latest.Version == "v1beta1" || latest.Version == "v1beta2"),
|
||||
QPS: 5,
|
||||
Burst: 10,
|
||||
},
|
||||
false,
|
||||
},
|
||||
|
@@ -61,7 +61,7 @@ type RESTClient struct {
|
||||
// such as Get, Put, Post, and Delete on specified paths. Codec controls encoding and
|
||||
// decoding of responses from the server. If this client should use the older, legacy
|
||||
// API conventions from Kubernetes API v1beta1 and v1beta2, set legacyBehavior true.
|
||||
func NewRESTClient(baseURL *url.URL, apiVersion string, c runtime.Codec, legacyBehavior bool, maxQPS float32) *RESTClient {
|
||||
func NewRESTClient(baseURL *url.URL, apiVersion string, c runtime.Codec, legacyBehavior bool, maxQPS float32, maxBurst int) *RESTClient {
|
||||
base := *baseURL
|
||||
if !strings.HasSuffix(base.Path, "/") {
|
||||
base.Path += "/"
|
||||
@@ -71,7 +71,7 @@ func NewRESTClient(baseURL *url.URL, apiVersion string, c runtime.Codec, legacyB
|
||||
|
||||
var throttle util.RateLimiter
|
||||
if maxQPS > 0 {
|
||||
throttle = util.NewTokenBucketRateLimiter(maxQPS, 10)
|
||||
throttle = util.NewTokenBucketRateLimiter(maxQPS, maxBurst)
|
||||
}
|
||||
return &RESTClient{
|
||||
baseURL: &base,
|
||||
|
Reference in New Issue
Block a user