feat(deploy): autoscale the WS gateway
im HPA: min 2 / max 6, CPU 70% as the primary signal and memory 80% as the connection-count guard (against the 128Mi request that is ~102Mi, and each live socket costs its buffers plus its own pubsub pump; the 512Mi limit is deliberately not the trigger). Scaling out is free here: cross-pod fan-out already goes through Redis pub/sub (Realtime::publish_room / subscribe_room), and the per-process rooms/users maps only hold this pod's own sockets, so a client on pod A keeps receiving events published by pod B. Scaling in is the one that costs something - the retired pod's clients must reconnect - so scale-down is much slower than apihost's: a 600s stabilization window and at most one pod per 120s, while scale-up reacts within 30s (+100% or +2 pods per 60s). A PDB (minAvailable 1) now keeps a node drain from taking both gateways at once. The image tag stays sha-20a153a: these commits only touch chart/ and deploy/, and the rendered im PodTemplate is byte-identical to the live one, so the upgrade rolled nothing and no websocket was dropped (verified: same pod names and ages, 0 restarts, and forcing the Deployment to 1 was restored to 2 by the HPA within 6s).
ZhenYi committed
Modified deploy/values/prod.yaml deploy/values/prod.yaml +28 −0 View deploy/values/prod.yaml
@@ -225,6 +225,34 @@
225225
226226im:
227227 enabled: true
228 # WS 网关自动扩缩。跨 pod 投递本来就走 Redis pub/sub(Realtime::publish_room /
229 # subscribe_room,本进程只持有自己那份 rooms/users 注册表),所以加副本不会让
230 # 谁收不到事件;缩容才会——被撤 pod 上的连接需要重连,因此 scaleDown 明显比
231 # apihost 保守:10 分钟稳定窗 + 每 2 分钟最多撤 1 个。
232 autoscaling:
233 enabled: true
234 minReplicas: 2
235 maxReplicas: 6
236 targetCPUUtilizationPercentage: 70
237 # 128Mi request 下约 102Mi 触发:每个在线连接 = socket 缓冲 + 自己的 pubsub pump
238 targetMemoryUtilizationPercentage: 80
239 behavior:
240 scaleUp:
241 stabilizationWindowSeconds: 30
242 policies:
243 - type: Percent
244 value: 100
245 periodSeconds: 60
246 - type: Pods
247 value: 2
248 periodSeconds: 60
249 selectPolicy: Max
250 scaleDown:
251 stabilizationWindowSeconds: 600
252 policies:
253 - type: Pods
254 value: 1
255 periodSeconds: 120
228256
229257runner:
230258 enabled: false