modify 修复前端展示配置与实际插件配置不一致的bug
This commit is contained in:
@@ -280,15 +280,23 @@ worker/<type>/<worker_id>/__admin__
|
||||
- **网关登记/注销 + 心跳租约**:网关启动时 `register_gateway()` 加入在线列表,并每 15s `heartbeat_gateway()` 刷新自身时间戳;超过租约(60s)未心跳的死网关会被自动清理(crash/kill -9 也不残留,避免配额失真)。当前由 `CHONGMING_GATEWAY_ID` 环境变量指定(多实例需唯一,尤其**同宿主多网关必须显式指定**;缺省回退 `hostname`,稳定且重启不变,不残留);关闭时 `unregister_gateway()` 移除,其余网关实时重算分摊。
|
||||
- **分摊算法**:`own_quota()` 将全局总量按在线网关 sorted(id) 均分,余量按序补前若干。`/admin/workers/<type>/scale`(body `{count:<全局总量>}`)写全局 count 后,各网关把自己的 session 副本调到自己的 quota。
|
||||
- **共享方式与后端**:单实例本机 `sqlite` 即可;**多实例必须共享同一 cache 后端**(同一共享卷的 sqlite 或 redis),否则各写各的 cache 无法收敛成全局量。
|
||||
- **启动优先级开关**:根 `config.toml` 的 `[cache].launch_worker_count` 决定网关启动时副本数的来源:
|
||||
- **配置优先来源模式**:根 `config.toml` 的 `[cache].launch_worker_count` 决定启动时 **`[workers.config]` 与 `count` 从哪一侧取值**(两种模式下"前端显示 / 插件实际使用 / 重启后行为"三处都自洽):
|
||||
|
||||
```toml
|
||||
[cache]
|
||||
backend = "sqlite" # "sqlite"(默认,本机共享) | "redis"(跨主机)
|
||||
path = "./cache_data/cache.db"
|
||||
launch_worker_count = "toml" # "toml"(默认)=启动用 toml 的 count 覆盖并写回 cache;"cache"=cache 为单一事实来源,toml 仅在缺失时引导
|
||||
launch_worker_count = "toml" # "toml"(默认)=以文件为准;"cache"=以缓存为准
|
||||
```
|
||||
|
||||
| 环节 | `"toml"`(默认) | `"cache"` |
|
||||
| --- | --- | --- |
|
||||
| 启动时 | 用 toml 的 `[workers.config]` 与 `count` **覆盖写入缓存**(前端读缓存,因此随之显示 toml 值) | 以缓存为准;插件初始化即读缓存值,缓存缺失才用 toml 引导并写回 |
|
||||
| 插件实际使用 | toml 值 | 缓存值 |
|
||||
| 管理接口改动的持久性 | 仅本次运行有效,重启网关被文件覆盖 | 跨重启保持 |
|
||||
|
||||
两种模式都不回写 `config.toml`:管理接口的改动只进缓存。`cache` 模式下启动日志会打印 toml 与缓存的差异键(以缓存为准);如需让 toml 的改动生效,先删除 `worker:cm:configs:<type>`(运行时配置)或 `worker:cm:counts:<type>`(副本数)缓存键再重启,或改用 `"toml"` 模式。`GET /admin/workers/<type>/config` 的响应带 `source`(cache/toml)与 `mode`,前端据此标注展示值的来路。
|
||||
|
||||
- **进程插件(external)实例粒度参与分摊**:网关只对 **inline** 插件用 cache 解析启动副本数(见「启动流程」第 5 步 `load_workers`),external 插件的启动副本数由外部编排按自身配置决定;但**运行时的缩放**上,external 并不退化为“每进程全额”,而是同样在**共享 cache 上登记实例参与方**来分摊,避免多实例把副本翻倍:
|
||||
- **实例登记 + 心跳租约**:每个 external 进程启动时向 `worker:cm:instances:<type>` 登记自身参与方(`[instance_id, ts]`),并每 15s 心跳续约;超过租约(60s)未心跳的死实例会被清理。`divmod` 按存活参与方 N 均分全局 count(余量补靠前实例),`N==1` 时退化为全额(单部署零影响)。
|
||||
- **实例标识默认唯一**:`--instance` / 环境变量 `CHONGMING_WORKER_INSTANCE` 显式指定(跨重启稳定、逐实例精细扩缩可持续命中);缺省回退 `{hostname}:{pid}`——**同一机器并行多个未指定 `--instance` 的进程也能靠 pid 区分**,不会因为 id 相同被并成一个参与方导致副本翻倍或前端只显示一个实例。注意缺省 id 随进程重启变化。
|
||||
@@ -821,7 +829,7 @@ uv pip install -e utils/<name> # 安装/更新工具包子包
|
||||
| 字段 | 位置 | 说明 |
|
||||
| -------------------- | --------------------- | --------------------------------------- |
|
||||
| `count` | `<插件>/config.toml` | Worker 副本数(`[workers]` 节) |
|
||||
| `launch_worker_count`| `根 config.toml` | 启动时副本数来源:`"toml"`=用 toml count 覆盖 cache(默认);`"cache"`=以 cache 为单一事实来源(`[cache]` 节) |
|
||||
| `launch_worker_count`| `根 config.toml` | 配置优先来源模式:`"toml"`=以文件为准(启动用 toml 的 `[workers.config]`/count 覆盖 cache,默认);`"cache"`=以 cache 为单一事实来源(插件初始化即读缓存,跨重启保持)(`[cache]` 节) |
|
||||
| `router_prefix` | `<插件>/config.toml` | API 路由前缀 |
|
||||
| `defaults.timeout` | `<插件>/config.toml` | 默认超时(秒) |
|
||||
| `defaults.cacheable` | `<插件>/config.toml` | 是否缓存 RPC 结果 |
|
||||
|
||||
Reference in New Issue
Block a user