Kubernetes offers two default paths for scaling Nodejs workloads, and both have structural limitations. The Horizontal Pod Autoscaler scales on CPU utilization, which does not directly measure event loop saturation: a Node.js pod can queue requests and miss latency SLOs while CPU reports moderate usage. KEDA extends HPA with richer triggers, including event-loop metrics, but inherits the same reactive control loop, detecting overload only after it has begun. By the time new pods start and absorb traffic, the system may already be degraded. Lowering thresholds shifts the operating point but does not change the dynamic: the scaler still reacts to a value it has already crossed, at the cost of permanent over-provisioning. We propose a predictive scaling algorithm that forecasts where load will be by the time new capacity is ready and scales proactively based on that forecast. Per-instance metrics are corrupted by the scaler's own actions: adding an instance redistributes load and changes every metric, even if external traffic is unchanged. We observe that operating on a cluster-wide aggregate that is approximately invariant under scaling eliminates this feedback loop, producing a stable signal suitable for short-term extrapolation. We define a metric model (a set of three functions that encode how a specific metric relates to scaling) and a five-stage pipeline that transforms raw, irregularly-timed, partial metric data into a clean prediction signal. In benchmarks against HPA and KEDA under steady ramp and sudden spike, the algorithm keeps per-instance load near the target threshold throughout. Under the steady ramp, median latency is 26ms, compared to 154ms for KEDA and 522ms for HPA.
翻译:Kubernetes为Node.js工作负载提供两种默认扩缩容方案,但两者均存在结构性局限。水平Pod自动伸缩器(HPA)以CPU利用率为缩放依据,这无法直接衡量事件循环饱和程度:当CPU显示中等负载时,Node.js Pod可能已开始排队请求并违反延迟SLO。KEDA通过引入事件循环指标等更丰富的触发条件扩展了HPA,但继承了相同的反应式控制循环——仅在过载发生后才能检测到问题。当新Pod启动并开始承接流量时,系统可能已经降级。降低阈值仅改变运行基准点却未改变动态机制:该伸缩器仍会对已超限的指标值做出反应,代价是永久性过度预配。我们提出一种预测性缩放算法,该算法预测新容量就绪时的负载水平,并基于该预测主动进行扩缩容。实例级指标会被缩放器自身操作所干扰:添加实例会重新分配负载并改变所有指标,即使外部流量未发生变化。我们观察到,对集群范围聚合指标(该指标在缩放操作下近似保持不变)进行处理可消除该反馈循环,从而生成适合短期外推的稳定信号。我们定义了一个指标模型(包含三个编码特定指标与缩放关系的函数)和一个五阶段流水线,用于将原始、非规则时间采样的不完整指标数据转换为干净的预测信号。在与HPA和KEDA的基准测试中(涵盖稳态爬坡和突发峰值两种场景),该算法始终能将实例负载维持在目标阈值附近。在稳态爬坡场景下,中位延迟为26毫秒,而KEDA为154毫秒,HPA为522毫秒。