modify: 清除diskcache依赖
This commit is contained in:
@@ -126,11 +126,14 @@ chongming-worker-rs/ # 独立仓库(或 utils/worker-rs/,与 Pyth
|
||||
| admin Queryable | `worker/<type>/<id>/__admin__`,指令 status/restart/stop/drain/get_config/config_set/rescale | 同一 keyexpr,`admin.rs::handle_admin` 全量分派 | ✅ keyexpr 与指令一致 |
|
||||
| 优雅排空 | drain:隔离新请求 → 等在途归零(30s 超时强制关闭) | `draining` 标记 + `wait_inflight_zero`(同 30s);先摘 liveliness/业务/admin 再等在途 | ✅ 行为一致 |
|
||||
| 配置热更 | config_set:仅 index0 落盘(原子写)+ 触发重启,`[workers.config]` 保留键校验 | `persist_worker_config_section`(tmp+rename 原子写)+ `merge_confirmed`/`count_allowed` 保留键校验 | ✅ 语义一致 |
|
||||
| 配置缓存 | chongming-cache(redis / diskcache)作为 counts/configs 单一事实来源 | `Cache` 抽象:Redis(feature `redis-cache`)+ 无缓存回退 | ✅ Redis 路径一致;本地 diskcache 因格式特性不可复用(多实例走 Redis) |
|
||||
| 配置缓存 | chongming-cache(redis / sqlite)作为 counts/configs 单一事实来源 | `Cache` 抽象:`sqlite`(feature `local-cache`,本机与 Python 共享同一 .db)+ Redis(feature `redis-cache`)+ 无缓存回退 | ✅ schema 一致,凡 JSON 值均可互通 |
|
||||
| quota 分摊 | 按在线网关/存活实例均分全局 count(余数给序较早方) | `distribute_quota` / `resolve_worker_count` 同算法 | ✅ 同协议键 `worker:cm:*` |
|
||||
| CLI | `--config` / `--instance` / `--count` | `examples/demo.rs`:`--config` / `--instance` / `--count` | ✅ 对齐 |
|
||||
|
||||
> 注:Python 默认的本地 `diskcache` 后端为 Python 库,Rust 无法读其存储文件格式;故 Rust 侧多实例协同统一走 Redis(`redis-cache` feature),单实例走 `Cache::None`,与 Python「多实例必须 redis/共享卷」约束一致。
|
||||
> 注:Rust 侧共享缓存已统一为与 Python `chongming-cache` 完全一致的 JSON 协议——本机走
|
||||
> `sqlite`(`local-cache` feature,跨语言共享同一 `.db`),跨主机走 Redis(`redis-cache`
|
||||
> feature);缺省无缓存走 `Cache::None`。原 Python 本地 diskcache 后端已被 SQLite 后端
|
||||
> 直接替换,不再存在「Rust 不可读其本地格式」的限制。
|
||||
|
||||
### 3.7 数据库对齐(`chongming_database` ↔ Rust `database.rs`)
|
||||
|
||||
|
||||
+24
-8
@@ -150,14 +150,30 @@ tokio::runtime::Builder::new_multi_thread().enable_all().build()?.block_on(async
|
||||
|
||||
### 5.2 多实例共享缓存 `[workers.cache]`
|
||||
|
||||
多实例部署(多进程/多机)**必须**启用 Redis 共享缓存,使副本数与配置跨实例收敛为单一事实来源:
|
||||
Rust 进程插件支持两种共享缓存后端(schema 与 Python `chongming-cache` 完全一致):
|
||||
|
||||
```toml
|
||||
[workers.cache]
|
||||
backend = "redis" # 仅支持 redis(Python 本地 diskcache 格式 Rust 不可读)
|
||||
url = "redis://127.0.0.1:6379/0"
|
||||
launch_worker_count = "cache" # 缓存为 count 单一事实来源
|
||||
```
|
||||
1. **本机共享 `sqlite`(feature `local-cache`)**:同一份 SQLite 文件由 Python 与 Rust 读写,
|
||||
实现单机多实例/跨语言收敛,无需 Redis。需 `cargo build --features local-cache`:
|
||||
```toml
|
||||
[workers.cache]
|
||||
backend = "sqlite" # schema 与 Python SqliteBackend 一致(旧名 diskcache 兼容)
|
||||
path = "./cache_data/cache.db" # 与网关该实例 `[cache].path` 指向同一文件
|
||||
launch_worker_count = "cache"
|
||||
```
|
||||
2. **跨主机 `redis`(feature `redis-cache`)**:多机部署必须用 Redis 共享缓存:
|
||||
```toml
|
||||
[workers.cache]
|
||||
backend = "redis"
|
||||
url = "redis://127.0.0.1:6379/0"
|
||||
prefix = "chongming:" # 与网关 config.toml [cache].redis_prefix 对齐(缺省空)
|
||||
launch_worker_count = "cache"
|
||||
```
|
||||
未指定 backend(缺省)时 Rust 走 `Cache::None`,退化为本地 toml 语义。
|
||||
|
||||
> `prefix` 必须与网关 `[cache].redis_prefix`(如 `"chongming:"`)一致,Rust 插件才会读写
|
||||
> 与网关同一批共享键。若网关未设前缀可省略。缓存值统一以 JSON 存储(Python 侧用
|
||||
> orjson、Rust 侧用 serde_json),**任意键**均可跨语言互通;与 Rust 共享的键请使用
|
||||
> JSON 兼容类型(dict/list/int/str/bool/null)。
|
||||
|
||||
编译启用:`bash build.sh dist "redis-cache"`(或 Cargo 依赖加 `chongming-worker-rs/redis-cache`)。
|
||||
未配置时单实例直接读写本地 `config.toml`(默认无缓存),行为一致。
|
||||
@@ -268,7 +284,7 @@ unzip myplugin.zip -d /app && cd /app && ./start.sh
|
||||
| 契约校验 | Python 进程内三方校验(硬失败);Rust 为**发布前自检**:无 handler 端点告警跳过,不发布残缺路由 |
|
||||
| 模型生成 | Rust 用 gen_models 生成强类型结构体 + **启动时指纹校验**(TOML 变更未重生成即告警,比 Python 更强) |
|
||||
| handler 注入 | worker_id 经 `Request.worker_id`、user_info 经 `Request.user_info` 注入(非函数参数) |
|
||||
| 配置缓存后端 | Rust 仅 Redis(无法读 Python 本地 diskcache);单实例走无缓存回退 |
|
||||
| 配置缓存后端 | Rust 支持 sqlite(`local-cache`,本机与 Python 共享同一 .db)+ Redis(`redis-cache`,跨主机);缺省无缓存回退 |
|
||||
| 数据库 | Rust 走 sqlx(见 §7),配置键与 Python `chongming_database` 对齐 |
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user