cachesize.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cachesize
  14. import (
  15. "k8s.io/apimachinery/pkg/runtime/schema"
  16. )
  17. // NewHeuristicWatchCacheSizes returns a map of suggested watch cache sizes based on total
  18. // memory.
  19. func NewHeuristicWatchCacheSizes(expectedRAMCapacityMB int) map[schema.GroupResource]int {
  20. // From our documentation, we officially recommend 120GB machines for
  21. // 2000 nodes, and we scale from that point. Thus we assume ~60MB of
  22. // capacity per node.
  23. // TODO: Revisit this heuristics
  24. clusterSize := expectedRAMCapacityMB / 60
  25. // We should specify cache size for a given resource only if it
  26. // is supposed to have non-default value.
  27. //
  28. // TODO: Figure out which resource we should have non-default value.
  29. watchCacheSizes := make(map[schema.GroupResource]int)
  30. watchCacheSizes[schema.GroupResource{Resource: "replicationcontrollers"}] = maxInt(5*clusterSize, 100)
  31. watchCacheSizes[schema.GroupResource{Resource: "endpoints"}] = maxInt(10*clusterSize, 1000)
  32. watchCacheSizes[schema.GroupResource{Resource: "endpointslices", Group: "discovery.k8s.io"}] = maxInt(10*clusterSize, 1000)
  33. watchCacheSizes[schema.GroupResource{Resource: "nodes"}] = maxInt(5*clusterSize, 1000)
  34. watchCacheSizes[schema.GroupResource{Resource: "pods"}] = maxInt(50*clusterSize, 1000)
  35. watchCacheSizes[schema.GroupResource{Resource: "services"}] = maxInt(5*clusterSize, 1000)
  36. watchCacheSizes[schema.GroupResource{Resource: "events"}] = 0
  37. watchCacheSizes[schema.GroupResource{Resource: "apiservices", Group: "apiregistration.k8s.io"}] = maxInt(5*clusterSize, 1000)
  38. watchCacheSizes[schema.GroupResource{Resource: "leases", Group: "coordination.k8s.io"}] = maxInt(5*clusterSize, 1000)
  39. return watchCacheSizes
  40. }
  41. func maxInt(a, b int) int {
  42. if a > b {
  43. return a
  44. }
  45. return b
  46. }