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 18, 2017
1 parent 929dc82 commit 01aeb23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 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
11 changes: 7 additions & 4 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 @@ -124,9 +123,13 @@ func TestDefaultWatchCacheSize(t *testing.T) {
etcdOptions := apiserveroptions.NewEtcdOptions(&storagebackend.Config{})
kubeDefaultCacheSize := etcdOptions.DefaultWatchCacheSize
if kubeDefaultCacheSize != 100 {
t.Fatalf("upstream DefaultWatchCacheSize changed from 100 to %q", kubeDefaultCacheSize)
t.Fatalf("upstream DefaultWatchCacheSize changed to %d", 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 01aeb23

Please sign in to comment.