Cell 温度管理

wesgine Cell 温度状态:Hot / Warm / Cool / Cold 四态及自动转换。


四种温度

温度含义激活成本
Hot有活跃 Run0
Warmgoroutine/DB 在内存0
Cool磁盘保留,无 goroutine100-500ms
ColdStopped1-3s

状态转换

Hot → Warm    Run 结束
Warm → Cool   idle 15min
Cool → Cold   idle N 天(可配置)

外设保持 Warm

需要 Warm 的外设:

当 Cell 有活跃 Cron 或 IMAP 时,Cell 无法降温到 Cool。


Cool 态行为

首请求自动 WarmUp

Cool 态 Cell 收到第一个请求时:

  1. Gateway 中间件检测到 Cool 状态
  2. 同步执行 WarmUp
  3. 请求继续处理

100-500ms 预算

WarmUp 需要:


Cold 态行为

Gateway 返回 503

Cold 态 Cell 收到请求时:

HTTP 503 Service Unavailable
Retry-After: 5

同时后台异步唤醒 Cell。

SDK 路径

SDK 路径对 Cold 态同步唤醒,不返回 503。


温度调度器

Hypervisor 运行温度调度器,管理所有 Cell 的温度转换。

调度逻辑

// 伪代码
for _, cell := range allCells {
    if cell.IdleDuration() > coolThreshold && cell.CanCool() {
        cell.Cool()
    }
    if cell.IdleDuration() > coldThreshold {
        cell.Stop()
    }
}

CanCool 判断

Cell 满足以下条件才可 Cool:


INV-SERVE-REACHABLE-01

wesgine serve 到达"可被探活"所需的时间是有界常数。

router.Start(绑端口)→ sdnotify.Ready() → ActivatePersisted(后台)

未被热身的 Cell:

代价:Cron/IMAP 推迟到下次热身才恢复。


IMAP 计数(imapWarmnessCount)

IMAP 收信注册与温度判断一律读存储,不读声明。


相关文档