Skip to content

Commit ef6d782

Browse files
Disable the watch cache for most resources by default
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.
1 parent 59c5192 commit ef6d782

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/cmd/server/kubernetes/master/master_config.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ import (
8080
"github.com/openshift/origin/pkg/version"
8181
)
8282

83-
const DefaultWatchCacheSize = 1000
84-
8583
// request paths that match this regular expression will be treated as long running
8684
// and not subjected to the default server timeout.
8785
const originLongRunningEndpointsRE = "(/|^)(buildconfigs/.*/instantiatebinary|imagestreamimports)$"
@@ -150,7 +148,7 @@ func BuildKubeAPIserverOptions(masterConfig configapi.MasterConfig) (*kapiserver
150148
server.Etcd.StorageConfig.KeyFile = masterConfig.EtcdClientInfo.ClientCert.KeyFile
151149
server.Etcd.StorageConfig.CertFile = masterConfig.EtcdClientInfo.ClientCert.CertFile
152150
server.Etcd.StorageConfig.CAFile = masterConfig.EtcdClientInfo.CA
153-
server.Etcd.DefaultWatchCacheSize = DefaultWatchCacheSize
151+
server.Etcd.DefaultWatchCacheSize = 0
154152

155153
server.GenericServerRunOptions.CorsAllowedOriginList = masterConfig.CORSAllowedOrigins
156154
server.GenericServerRunOptions.MaxRequestsInFlight = masterConfig.ServingInfo.MaxRequestsInFlight

test/integration/watch_cache_test.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
1616

1717
configapi "github.com/openshift/origin/pkg/cmd/server/api"
18-
serverkube "github.com/openshift/origin/pkg/cmd/server/kubernetes/master"
1918
testutil "github.com/openshift/origin/test/util"
2019
testserver "github.com/openshift/origin/test/util/server"
2120
)
@@ -123,10 +122,14 @@ func TestDefaultWatchCacheSize(t *testing.T) {
123122
// test that the origin default really applies and that we don't fall back to kube's default
124123
etcdOptions := apiserveroptions.NewEtcdOptions(&storagebackend.Config{})
125124
kubeDefaultCacheSize := etcdOptions.DefaultWatchCacheSize
126-
if kubeDefaultCacheSize != 100 {
127-
t.Fatalf("upstream DefaultWatchCacheSize changed from 100 to %q", kubeDefaultCacheSize)
125+
if kubeDefaultCacheSize != 0 {
126+
t.Fatalf("upstream DefaultWatchCacheSize changed to %q", kubeDefaultCacheSize)
128127
}
129-
testWatchCacheWithConfig(t, master, serverkube.DefaultWatchCacheSize, kubeDefaultCacheSize)
128+
if master.KubernetesMasterConfig.APIServerArguments == nil {
129+
master.KubernetesMasterConfig.APIServerArguments = configapi.ExtendedArguments{}
130+
}
131+
master.KubernetesMasterConfig.APIServerArguments["watch-cache-sizes"] = []string{"namespaces#100"}
132+
testWatchCacheWithConfig(t, master, 100, 0)
130133
}
131134

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

143-
testWatchCacheWithConfig(t, master, 2000, serverkube.DefaultWatchCacheSize)
146+
testWatchCacheWithConfig(t, master, 2000, 0)
144147
}

0 commit comments

Comments
 (0)