Skip to content

Commit

Permalink
Disable the watch cache for most resources by default
Browse files Browse the repository at this point in the history
Any resource named by the heuristics gets a watch cache by default.
Admins can restore the previous behavior by setting
`--default-watch-cache-size` to a positive integer. This reduces the
amount of total memory allocated on large cluster significantly at minor
cost in CPU on the etcd process and an increase in network bandwidth to
etcd.
  • Loading branch information
smarterclayton committed Sep 17, 2017
1 parent 59c5192 commit ef6d782
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 1 addition & 3 deletions pkg/cmd/server/kubernetes/master/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ import (
"github.com/openshift/origin/pkg/version"
)

const DefaultWatchCacheSize = 1000

// request paths that match this regular expression will be treated as long running
// and not subjected to the default server timeout.
const originLongRunningEndpointsRE = "(/|^)(buildconfigs/.*/instantiatebinary|imagestreamimports)$"
Expand Down Expand Up @@ -150,7 +148,7 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver
server.Etcd.StorageConfig.KeyFile = masterConfig.EtcdClientInfo.ClientCert.KeyFile
server.Etcd.StorageConfig.CertFile = masterConfig.EtcdClientInfo.ClientCert.CertFile
server.Etcd.StorageConfig.CAFile = masterConfig.EtcdClientInfo.CA
server.Etcd.DefaultWatchCacheSize = DefaultWatchCacheSize
server.Etcd.DefaultWatchCacheSize = 0

server.GenericServerRunOptions.CorsAllowedOriginList = masterConfig.CORSAllowedOrigins
server.GenericServerRunOptions.MaxRequestsInFlight = masterConfig.ServingInfo.MaxRequestsInFlight
Expand Down
13 changes: 8 additions & 5 deletions test/integration/watch_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"

configapi "github.com/openshift/origin/pkg/cmd/server/api"
serverkube "github.com/openshift/origin/pkg/cmd/server/kubernetes/master"
testutil "github.com/openshift/origin/test/util"
testserver "github.com/openshift/origin/test/util/server"
)
Expand Down Expand Up @@ -123,10 +122,14 @@ func TestDefaultWatchCacheSize(t *testing.T) {
// test that the origin default really applies and that we don't fall back to kube's default
etcdOptions := apiserveroptions.NewEtcdOptions(&storagebackend.Config{})
kubeDefaultCacheSize := etcdOptions.DefaultWatchCacheSize
if kubeDefaultCacheSize != 100 {
t.Fatalf("upstream DefaultWatchCacheSize changed from 100 to %q", kubeDefaultCacheSize)
if kubeDefaultCacheSize != 0 {
t.Fatalf("upstream DefaultWatchCacheSize changed to %q", kubeDefaultCacheSize)
}
testWatchCacheWithConfig(t, master, serverkube.DefaultWatchCacheSize, kubeDefaultCacheSize)
if master.KubernetesMasterConfig.APIServerArguments == nil {
master.KubernetesMasterConfig.APIServerArguments = configapi.ExtendedArguments{}
}
master.KubernetesMasterConfig.APIServerArguments["watch-cache-sizes"] = []string{"namespaces#100"}
testWatchCacheWithConfig(t, master, 100, 0)
}

func TestWatchCacheSizeWithFlag(t *testing.T) {
Expand All @@ -140,5 +143,5 @@ func TestWatchCacheSizeWithFlag(t *testing.T) {
}
master.KubernetesMasterConfig.APIServerArguments["watch-cache-sizes"] = []string{"namespaces#2000"}

testWatchCacheWithConfig(t, master, 2000, serverkube.DefaultWatchCacheSize)
testWatchCacheWithConfig(t, master, 2000, 0)
}

0 comments on commit ef6d782

Please sign in to comment.