Skip to content

Commit 01aeb23

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 929dc82 commit 01aeb23

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 7 additions & 4 deletions
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
)
@@ -124,9 +123,13 @@ func TestDefaultWatchCacheSize(t *testing.T) {
124123
etcdOptions := apiserveroptions.NewEtcdOptions(&storagebackend.Config{})
125124
kubeDefaultCacheSize := etcdOptions.DefaultWatchCacheSize
126125
if kubeDefaultCacheSize != 100 {
127-
t.Fatalf("upstream DefaultWatchCacheSize changed from 100 to %q", kubeDefaultCacheSize)
126+
t.Fatalf("upstream DefaultWatchCacheSize changed to %d", 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)