在Kubernetes集群中使用CPU限制会严重损害应用性能。[1]根据实验测试,CPU限制导致应用在节点仍有空闲CPU的情况下频繁被冻结。[1]具体测试结果显示,受限应用在流量高峰期被冻结的100毫秒时间窗口占比高达89%,其p99延迟比无限制应用慢2.4倍。[1]
针对这一问题,建议的解决方案是移除CPU限制,同时保留CPU请求和内存限制。[1]这种做法可以显著提升应用性能,包括尾部延迟降低和启动速度提升2倍,同时每个集群每年可节省数万美元的硬件成本。[1]实施步骤包括设置DOTNET_PROCESSOR_COUNT默认值、添加节流监控仪表板、配置LimitRange和ResourceQuota、逐命名空间移除CPU限制,以及基于30天P95使用量调整资源请求。[1]对于特定场景,仍应保留CPU限制,包括不可信的第三方工作负载、基准测试pod,以及采用固定CPU的Guaranteed QoS pod。[1]
A comprehensive analysis has demonstrated that eliminating CPU limits while retaining CPU requests and memory limits in Kubernetes can substantially improve application performance and reduce infrastructure expenses.[1]
According to experimental testing, CPU limits cause applications to be frozen multiple times per second despite available CPU capacity on nodes.[1] Under peak traffic conditions, applications subject to CPU limits experienced throttling during 89% of 100-millisecond windows, resulting in p99 latency that was 2.4 times slower compared to applications without such restrictions operating under identical load.[1] Removing these constraints produced significant improvements in tail latency and startup speed, with startup times improving by a factor of two.[1] The financial impact is also substantial, with potential annual savings reaching tens of thousands of dollars per cluster depending on specific configuration.[1]
The recommended implementation strategy involves a phased approach: first, configure default DOTNET_PROCESSOR_COUNT values; second, add throttling monitoring dashboards; third, implement LimitRange and ResourceQuota controls; fourth, progressively eliminate CPU limits across namespaces; and finally, adjust resource requests based on 30-day P95 usage metrics.[1] However, certain workloads warrant retaining CPU limits, including untrusted third-party workloads, benchmark pods, and Guaranteed Quality of Service pods with fixed CPU allocations.[1]