边缘计算优化升级 2.0 — Pipeline Worker 工业控制内核
V2.2 Pipeline Worker 为 EdgeX 工业边缘的 PRIMARY 正确架构(ARMv7 / RK3588 单线程内联 Pipeline)。工业稳定优先:无对象流积压、无双缓冲四层驻留、热路径零堆分配。
V2.1 Gateway Rich Profile 保留为可选富网关部署形态,见 附录 A——非嵌入式默认路径。
§0 背景:从 1.x 规则引擎到 Pipeline Worker
0.1 1.x 问题
EdgeX 1.x 以 EdgeComputeManager + EdgeRule + expr 为核心(edge_compute_manager.go),功能完整但架构耦合且不适合嵌入式热路径:
- 公式 / 阈值 / 窗口 CEP 与动作执行混在
executeRule 同一层。
- 频率控制分散于
CheckInterval、调度器 batch_window_ms、动作 interval 三处。
ruleIndex 逐点订阅 + workerPool chan *ruleTask 堆对象队列 → GC 抖动。
valueCache / windows / ruleStates 多 map 常驻 → 256MB 设备 OOM 风险。
- 配置持久化于 bbolt,但运行时仍是「规则引擎 + expr 解释」心智。
0.2 V2.2 目标(PRIMARY)
将 1.x 能力收敛为 单 goroutine Pipeline Worker,产品心智从「规则配置」转为 工业控制 inline 执行模型——以栈上 Trigger 为触发语义,贯穿五段内联主链。
工程约束(铁律):
- 配置:
config.db(bbolt)+ 内存热路径;禁止业务 YAML 入代码。
- 规则:init 时预展开为跳转表 /
[]RuleSlot,运行时零 expr 解释。
- 北向零侵入:MQTT / OPC UA 复用现有发布链路(
stream 类型)。
- 南向主路径:PLC / MQTT / 串口 IO(
control 类型)。
- 工业稳定优先:72h soak、5–20ms 控制延迟、热路径零堆分配。
0.3 与现有代码基线关系
| 现有模块 |
文件 |
V2.2 迁移策略 |
| 南向采集 |
scan_engine.go |
复用 → Pipeline Input Stream |
| 数据扇出 |
pipeline.go · DataPipeline |
替换 → internal/pipeline/ring_buffer.go |
| 规则引擎 |
edge_compute_manager.go |
退役主路径 → Pipeline Worker |
| 虚拟派生 |
virtual_shadow_engine.go |
编译期内联 → eval.go 预展开公式 |
| 事件审计 |
edge_event_recorder.go |
复用 → Feedback 异步 bblot |
| 调度背压 |
edge_rule_scheduler.go |
内联 → allow() rate_limit + dedup |
读者关切:Gateway 层复杂联动(多步 Rollback、SES 闩锁闭环、Intent 生命周期诊断)请参阅 附录 A V2.1;嵌入式节点不做 Intent 队列与 Feedback → Intent 回写。
§1 工业稳定优先铁律(§1 不可违背)
以下原则优先于一切性能优化与功能扩展:
| # |
铁律 |
含义 |
| 1 |
无对象流积压 |
禁止 Intent 队列、ExecutionContext map 池、Snapshot 扇出多消费者 |
| 2 |
无双缓冲四层驻留 |
禁止 Snapshot / Intent / Context / Trace 并行堆驻留;仅 PointCache 覆盖写 |
| 3 |
执行优于抽象 |
inline compute-execute;规则 init 预展开,运行时只读跳转 |
| 4 |
GC 零分配热路径 |
Pipeline 主循环禁止 new() / make() / map 写入 |
| 5 |
72h 稳定性 |
soak 无泄漏;GC STW ≤ 5ms;控制 P95 ≤ 20ms(不含协议 IO) |
| 6 |
bbolt 仅配置与审计 |
config.db 冷加载;runtime.db 异步分钟摘要;不进热路径队列 |
| 7 |
Feedback 不回写 Intent |
仅 bblot + last_state + counter;状态变更由下一轮 Input 自然驱动 |
硬约束环境:
- 内存:256MB ~ 2GB(ARMv7 单/双核 · RK3588 big.LITTLE)
- 协议:PLC / MQTT / 串口 IO 为主
- 配置:bbolt + 内存结构;禁止 YAML 入代码
§2 五段内联 Pipeline(唯一允许的主路径)
V2.2 不是六段闭环,而是 单 Pipeline Worker 五段内联链:
① Input Stream ← ScanEngine / 南向驱动事件流(ring buffer)
② Evaluate (inline) ← 公式 / 阈值 / 边沿,栈上计算
③ Decide (inline) ← 预展开规则路由(init 编译,无 Decision Gate 模块)
④ Execute (immediate) ← control / stream / store 三类型直执行
⑤ Feedback (lightweight) ← bblot 日志 + last_state + 轻量 counter(NO Intent loopback)
与 V2.1 六段对比(为何嵌入式不用 V2.1)
| V2.1 段 |
V2.2 对应 |
嵌入式取舍 |
| Source Intake |
① Input Stream |
复用 ScanEngine |
| Snapshot Engine + 扇出 |
PointCache 覆盖写 |
无 SnapshotEvent 队列 |
| Intent Core + Composer |
② Evaluate inline |
无 ExecutionIntent 堆对象 |
| Decision Gate |
③ Decide 预展开 |
无独立 Guards 模块 |
| Execution Runtime |
④ Execute immediate |
仅 3 种 Step Type |
| Feedback → SES → Intent |
⑤ Feedback lightweight |
禁止 Intent 回写闭环 |
§3 Pipeline Worker 核心循环
for event := range input {
if !allow(event) { continue } // rate limit + dedup inline
value := eval(event) // inline formula/threshold
if !match(value) { continue } // pre-expanded rules
execute(value) // control/stream/store only
feedback(event, result) // log + last_state only
}
设计要点:
- 单 goroutine:无 worker pool、无 channel 堆任务。
- 算完即丢:
Trigger 栈生命周期,不进入任何队列。
- 满则 drop-oldest:ring buffer 固定容量,不阻塞 ScanEngine。
- 冷路径可分配:配置 reload / bblot 批量写允许短暂 GC。
§4 核心数据结构(零/低分配)
4.1 PointCache — 替代 SnapshotEvent
// model/point_cache.go
type PointCache struct {
value int32
ts int64
}
| 维度 |
1.x / V2.1 SnapshotEvent |
V2.2 PointCache |
| 结构 |
ID + SourceID + Points map |
value + ts 两字段 |
| 流 |
扇出多消费者 |
lock-free 点表覆盖写 |
| 窗口 |
runtime window_ms 队列 |
init 预展开,runtime inline |
| 内存 |
每事件堆分配 |
固定 []PointCache 数组 |
4.2 Trigger — 替代 ExecutionIntent
// model/trigger.go
type Trigger struct {
source uint32 // 点位 / 规则源 ID(编译期索引)
value int32 // 当前值或派生值
code uint8 // 触发码(阈值 / 边沿 / 公式结果)
}
| 维度 |
V2.1 ExecutionIntent |
V2.2 Trigger |
| 分配 |
堆(map + string ID) |
栈 / 值类型 |
| 生命周期 |
CREATED → COMPLETED |
单事件作用域 |
| 语义 |
cause + Points map |
source + value + code |
| 队列 |
Intent Core 队列 |
无队列 |
4.3 RuleSlot — init 预展开规则表
// internal/pipeline/decide.go
type RuleSlot struct {
sourceIdx uint32
op uint8 // gt / lt / eq / edge_rise / edge_fall
threshold int32
actionIdx uint16
minInterval int64 // Guards rate_limit 编译入内
lastFire int64 // inline 节流状态
}
type RuleTable struct {
slots []RuleSlot // init 预分配,runtime 只读
}
规则自 bbolt pipeline_rules bucket 加载,init 时编译为跳转表;运行时 match() 仅数组扫描 + 整数比较,无 expr 引擎。
§5 执行类型(仅此三种)
| 类型 |
职责 |
1.x 对应 |
| control |
WritePoint / 串口 / PLC 写 |
device_control |
| stream |
MQTT / WS / OPC UA PushFrame |
mqtt / http / websocket |
| store |
bblot / 本地持久化 |
log / 本地库 |
不在 V2.2 独立存在的 Step:delay · check · rollback · ses_sync — 由 control 链内联或 编译期展开;复杂多步场景在 Gateway V2.1 处理。
移除:短信 / 邮件 / 企微(局域网嵌入式)。
§6 Go 包结构
internal/
├── pipeline/ # V2.2 单 Worker 入口(PRIMARY)
│ ├── worker.go # 五段内联主循环
│ ├── ring_buffer.go # 输入事件环形缓冲(固定容量)
│ ├── eval.go # inline Evaluate(公式 / 阈值 / 边沿)
│ ├── decide.go # 预展开规则跳转表 · RuleTable
│ ├── execute.go # control / stream / store
│ └── feedback.go # bblot + last_state + counter
├── pointcache/
│ └── cache.go # lock-free 点表([]PointCache 固定数组)
└── core/
├── scan_engine.go # 复用 → pipeline input
├── pipeline.go # 1.x DataPipeline(过渡保留)
└── edge_compute_manager.go # 1.x ECM(过渡 / Gateway profile)
model/
├── trigger.go
└── point_cache.go
// config.db(bbolt)V2.2 bucket:
// pipeline_rules · point_bindings · pipeline_stats
// runtime.db(bbolt):
// bblot(异步分钟摘要,复用 edge_event_recorder 模式)
依赖方向(单向):
ScanEngine → ring_buffer → pipeline worker (eval → decide → execute → feedback)
config_store → init 编译 RuleTable / PointCache 布局
feedback → runtime.db(异步,不阻塞热路径)
与 V2.1 包隔离:internal/snapshot/ · intent/ · decision/ · execution/ · feedback/ 仅 Gateway Rich Profile 使用,build tag gateway 可选编译。
§7 一句话定义
EdgeX V2.2 是一个基于 单 Pipeline Worker 的工业控制 inline 执行系统:ScanEngine 事件经 ring buffer 进入五段内联链,Evaluate 栈上派生,Decide 读预展开规则表,Execute 直跑 control/stream/store,Feedback 仅审计与末态——无 Intent 对象流、无 Snapshot 扇出、无 Feedback 控制闭环。
§8 功能对齐:规则配置语义 → Pipeline Worker 映射
读者定位:UI / 产品文档中的用户配置术语(Sources、Condition、Actions 等)与 V2.2 Pipeline Worker 实现语义的一一对应。配置仍写入 bbolt(config.db),禁止 YAML 入代码;UI 字段名与 EdgeCompute.vue / model.EdgeRule 保持一致。
8.0 基础概念映射
| 用户概念(UI / 文档) |
V2.2 Pipeline 等价物 |
bbolt 配置字段 |
编译时机 |
运行时行为 |
| Sources(数据源 + 别名 t1、p1) |
point_bindings 表 + SourceIdx |
point_bindings.ref · alias · idx |
init |
ScanEngine 事件携带 SourceIdx;别名仅用于 init 表达式解析 |
| Condition(布尔表达式,Calculation 除外) |
RuleSlot.op + threshold 或 EvalSlot 边沿位 |
pipeline_rules.op · threshold · edge_trigger |
init |
match() 整数比较,无 expr |
| Actions(动作链) |
ActionSlot[] + StepChain(gateway) |
pipeline_actions · step_chain |
init |
embedded:actions[actionIdx] 单步或内联链 |
| Trigger mode: always |
RuleSlot.edge_trigger = false |
pipeline_rules.trigger_mode: "always" |
init |
条件满足即 execute() |
| Trigger mode: on_change |
RuleSlot.edge_trigger = true + Feedback.lastState |
pipeline_rules.trigger_mode: "on_change" |
init |
仅边沿(false→true)触发,告警去重 |
| Check frequency(1s / 5s / 1m) |
allow() 门控 + RuleSlot.minInterval |
pipeline_rules.check_interval_ms |
init |
allow() 按源节流;规则级 LastFire 二次节流 |
| Priority(数值越大越高) |
RuleTable.slots 按 priority 降序排列 |
pipeline_rules.priority |
init |
Match() 扫描命中首条(高优先级先匹配) |
8.1 规则类型映射
规则类型(UI type) |
用户语义 |
V2.2 Pipeline 写法 |
bbolt 关键字段 |
init / runtime |
| threshold |
条件为真 → 动作链 |
RuleSlot{op, threshold, actionIdx} |
op, threshold, action_id |
init 编译;runtime match() |
| calculation |
公式计算,不触发 Condition 动作链 |
EvalSlot{EvalFormula, InIdx, Coef} |
expression, sources[].alias |
init 解析 t1*1.8+32 → 定点系数;runtime eval() |
| window |
时间/计数窗口聚合 |
EvalSlot{EvalWindowAvg/Min/Max, WindowN, buf} |
window.type, window.size, window.aggr_func |
init 分配环形缓冲;runtime inline 累加 |
| state |
持续时间/次数防抖(状态 sustain) |
EvalSlot debounce counter + RuleSlot 联动 |
state.duration, state.count |
runtime inline 计数/计时;满足后 match() |
8.2 表达式语法 → 编译期 EvalSlot
| 用户表达式 |
1.x(expr 运行时) |
V2.2(init 预编译) |
ARM 热路径 |
v / value |
当前点值 |
ev.Raw 或 PointCache.Load(sourceIdx) |
栈上 int32 |
t1, p1 |
别名 env map |
InIdx[] 绑定点索引 |
uint32 数组索引 |
bitget(v, n) |
expr 函数 |
EvalBitGet opcode + 位偏移 n |
单条 AND/SHIFT |
bitset / bitclr / bitand / bitor |
expr 函数 |
对应 EvalBit* opcode 序列 |
无函数调用 |
t1 > 80 |
Condition 字符串 |
RuleSlot{opGT, threshold: 80000}(×1000 定点) |
整数比较 |
t1*1.8+32 |
Expression 字符串 |
EvalFormula{coef:[1000,1800,32000], InIdx:[t1]} |
定点乘加 |
铁律:Pipeline Worker 热路径禁止 expr / govaluate;无法静态展开的表达式在 init 阶段报错,UI 提示「需 Gateway Profile 或简化表达式」。
8.3 动作类型映射
动作类型(UI actions[].type) |
用户语义 |
V2.2 Execute 类型 |
bbolt 字段 |
embedded / gateway |
| log |
本地日志 |
store(bblot 分钟摘要) |
action.kind: "store" |
✅ embedded |
| device_control / command |
南向写点 |
control |
action.target_ref, action.payload |
✅ embedded |
| mqtt |
MQTT 推送 |
stream |
action.connector_id, topic, payload_tpl |
✅ embedded |
| http |
HTTP 推送 |
stream |
action.url, method |
✅ embedded |
| database |
本地库持久化 |
store |
action.bucket, key_tpl |
✅ embedded |
| sequence |
多步顺序执行 |
StepChain[] 预展开 |
step_chain[] |
🟡 embedded 简化为 control 内联;gateway 完整链 |
| delay |
步骤间延时 |
StepChain.delay_ms 或 busy-wait |
step.delay_ms |
🟡 embedded:ms 级 busy-wait;gateway:独立 step |
| check |
条件校验 / 失败分支 |
StepChain.check_op + on_fail 索引 |
step.check_*, on_fail_idx |
❌ embedded 不支持;gateway 完整 |
8.4 完整示例:温度告警 t1 > 80,每 5s 检查,MQTT 推送
用户配置(UI 语义,持久化于 bbolt EdgeRules → 编译为 pipeline_rules):
{
"id": "rule-temp-alarm",
"name": "高温告警",
"type": "threshold",
"enable": true,
"priority": 10,
"check_interval": "5s",
"trigger_mode": "on_change",
"sources": [{ "alias": "t1", "channel_id": "ch1", "device_id": "dev1", "point_id": "temp" }],
"condition": "t1 > 80",
"actions": [{ "type": "mqtt", "config": { "topic": "alarm/temp", "payload": "high temp" } }]
}
init 编译结果(内存结构,runtime 只读):
point_bindings: "ch1/dev1/temp" → idx=42, alias "t1" → idx=42
EvalSlot[42]: EvalPassthrough(threshold 规则无公式)
RuleSlot:
sourceIdx=42, op=gt, threshold=80000 (80×1000)
actionIdx=3, minInterval=5_000_000_000 (5s)
edge_trigger=true, priority=10
ActionSlot[3]: kind=stream, connector=mqtt-default, payload_tpl="high temp"
Pipeline Worker 运行时(单事件):
① Input: RingEvent{SourceIdx=42, Raw=85000, Ts=...}
② allow(): check_interval 距上次 ≥5s → pass;on_change 查 lastState[42] 未告警 → pass
③ eval(): passthrough → value=85000
④ match(): 85000 > 80000 → hit RuleSlot → actionIdx=3
⑤ execute: stream → MQTT publish "alarm/temp"
⑥ feedback: lastState[42]=ALARM; bblot 异步写入; counter++
8.5 最佳实践 → Pipeline 行为
| 最佳实践(用户文档) |
Pipeline 实现要点 |
| 一规则一职责 |
每条 UI 规则 → 独立 RuleSlot + 单一 actionIdx(或 gateway StepChain) |
| 告警去重:on_change |
edge_trigger=true + Feedback.lastState |
| 防抖:State 类型或 duration/count |
EvalSlot debounce counter;state.duration / state.count init 编译 |
| 复杂联动:Sequence + Check + On Fail |
Gateway Profile 完整 StepChain;embedded 建议拆多条规则 |
| 性能:非紧急规则拉长 check frequency |
check_interval_ms ↑ → allow() 拒绝率 ↑,CPU ↓ |
8.6 1.x 模块 → V2.2 段映射(工程视角)
| 1.x 功能 |
1.x 实现 |
V2.2 段 |
目标包 |
| 南向/北向采集 |
ScanEngine |
① Input Stream |
internal/core/scan_engine.go |
| 数据格式 / 扇出 |
DataPipeline |
ring buffer + PointCache |
internal/pipeline/ |
| 公式 / 阈值 |
EdgeRule + expr |
② Evaluate inline |
internal/pipeline/eval.go |
| 窗口 / 边沿 |
EdgeRule window |
② Evaluate(init 参数) |
internal/pipeline/eval.go |
| 静态路由 / 限频 |
executeRule 内 |
③ Decide 预展开 |
internal/pipeline/decide.go |
| 动作执行 |
ECM worker pool |
④ Execute |
internal/pipeline/execute.go |
| 失败重试 / 审计 |
edge_event_recorder |
⑤ Feedback |
internal/pipeline/feedback.go |
| 虚拟派生 |
virtual_shadow_engine |
init 编译公式槽 |
eval.go + point_bindings |
8.7 配置模型
- 持久化:
config.db → pipeline_rules、point_bindings、pipeline_stats。
- 运行时:内存
RuleTable、[]PointCache、ring buffer;禁止 runtime map 增长。
- 禁止:YAML 热加载、expr 在 Pipeline 热路径。
§9 现状走查与缺口
9.1 已实现(1.x · 可复用)
| 模块 |
文件 |
完成度 |
| 数据输入 |
scan_engine.go · shadow_core.go |
✅ |
| 数据管道(旧) |
pipeline.go · DataPipeline |
✅ 待替换 |
| 规则引擎 |
edge_compute_manager.go |
✅ 待退役主路径 |
| 虚拟影子 |
virtual_shadow_engine.go |
✅ 公式逻辑可编译迁移 |
| 调度 / bblot |
edge_rule_scheduler.go · edge_event_recorder.go |
✅ Feedback 复用 |
| ARM 基准 |
armv7_bench_test.go |
✅ 门禁可扩展 Pipeline |
| 配置 / UI |
config_store.go · EdgeCompute.vue |
✅ / 🟡 |
9.2 缺口(相对 V2.2 PRIMARY)
| 缺口 |
优先级 |
Pipeline Worker 主循环(worker.go) |
P0 |
| Ring buffer 输入(替代 DataPipeline map 缓冲) |
P0 |
| PointCache lock-free 点表 |
P0 |
| Trigger + RuleTable 模型 |
P0 |
| init 规则编译器(EdgeRule 子集 → RuleSlot) |
P0 |
| Execute 三类型(control / stream / store) |
P0 |
| 轻量 Feedback(bblot 异步 + last_state) |
P0 |
| ScanEngine → ring buffer 对接 |
P0 |
| build tag / profile 切换(embedded vs gateway) |
P1 |
| Pipeline 诊断 API + 精简 UI |
P2–P3 |
9.3 ECM → Pipeline Worker 迁移路径
Phase 0(并行):
ScanEngine ──► DataPipeline ──► ECM(1.x 保持可用)
ScanEngine ──► ring_buffer ──► Pipeline Worker(新主路径,build tag embedded)
Phase 1(默认切换):
嵌入式镜像默认编译 embedded profile
ECM 仅 gateway profile 保留
Phase 2(清理):
DataPipeline 扇出 handler 移除 ECM 订阅
edge_compute_manager 标记 deprecated(gateway only)
§10 实施任务(P0–P3)
P0 — Pipeline Worker 骨架(PRIMARY 交付)
| ID |
任务 |
包/文件 |
验收 |
| P0-1 |
Pipeline Worker 主循环 |
internal/pipeline/worker.go |
五段内联;单 goroutine;72h 无泄漏 |
| P0-2 |
Ring Buffer 输入 |
internal/pipeline/ring_buffer.go |
固定容量;drop-oldest;零堆分配 |
| P0-3 |
PointCache lock-free |
internal/pointcache/cache.go |
atomic 读写;固定数组;无 map |
| P0-4 |
Trigger 模型 |
model/trigger.go · model/point_cache.go |
栈值类型;替代 ExecutionIntent / SnapshotEvent |
| P0-5 |
规则预展开 |
internal/pipeline/decide.go |
init 编译 EdgeRule 子集 → RuleTable |
| P0-6 |
Evaluate inline |
internal/pipeline/eval.go |
公式 / 阈值 / 边沿;init 绑定点位索引 |
| P0-7 |
Execute 三类型 |
internal/pipeline/execute.go |
control / stream / store |
| P0-8 |
轻量 Feedback |
internal/pipeline/feedback.go |
bblot 异步 + last_state + counter;无 Intent 回写 |
| P0-9 |
ScanEngine 对接 |
scan_engine.go → ring buffer |
事件流接入;满不阻塞采集 |
| P0-10 |
ConfigStore bucket |
config_store.go |
pipeline_rules · point_bindings |
| P0-11 |
迁移指南 + 5 条样例 |
本文 §8 · Pipeline 配置指南 · ARMv7 参考实现 |
1.x 规则 → RuleSlot 样例 |
P1 — 能力与 Profile
| ID |
任务 |
| P1-1 |
build tag / runtime profile(embedded vs gateway) |
| P1-2 |
EdgeRule 子集 → pipeline_rules 编译器 |
| P1-3 |
VirtualShadow 公式 → eval 槽编译 |
| P1-4 |
嵌入式延迟 benchmark(5–20ms P95) |
| P1-5 |
72h soak 脚本(ARMv7 / RK3588 目标板) |
| P1-6 |
ECM 双轨过渡开关(gateway 保留) |
P2 — 可观测
| ID |
任务 |
| P2-1 |
Pipeline counter metrics(/api/diagnostics/pipeline) |
| P2-2 |
精简配置 UI(规则列表 + 点绑定) |
| P2-3 |
首页 Pipeline 统计(执行 / 拒绝 / 延迟 histogram) |
P3 — 清理
| ID |
任务 |
| P3-1 |
嵌入式镜像默认关闭 ECM 主路径 |
| P3-2 |
DataPipeline ECM handler 移除(embedded profile) |
| P3-3 |
扩展 ARMv7 benchmark gate 含 Pipeline 热路径 |
§11 工业联动场景
链路统一为:Input → allow → eval → match → execute → feedback
| 场景 |
eval 触发 |
decide |
execute |
feedback |
| 阈值告警联动 |
温度 > 阈值 |
RuleSlot match |
stream MQTT |
bblot + counter |
| 南向设备控制 |
设定值变更 |
parametric 规则 |
control WritePoint |
last_state |
| 本地持久化 |
累计量派生 |
map 规则 |
store |
bblot |
| 串口 / PLC 写 |
边沿检测 |
edge_rise slot |
control |
last_state |
工业约束:嵌入式不做 Scenario 递归、不做 RollbackPlan 独立模块;多步启动/回退在 Gateway V2.1 处理。
Pipeline 运行时状态(轻量)
无 Intent Lifecycle 全链路;仅 counter + last_state:
EVENT_IN → ALLOWED | DEDUPED | RATE_LIMITED
→ EVAL_OK | EVAL_SKIP
→ MATCHED → EXEC_OK | EXEC_FAIL
→ FEEDBACK_WRITTEN
§12 存储与监控
12.1 bbolt(继承 1.x 模式)
runtime.db bucket bblot:分钟摘要,异步批量写(复用 edge_event_recorder.go),失败不阻塞 Pipeline。
- 字段:
source_idx、action_idx、result_code、ts(紧凑编码,无 string intent_id)。
- 无
intent_lifecycle bucket(Gateway V2.1 专用)。
12.2 首页监控(嵌入式精简)
| 区域 |
指标 |
来源 |
| Input |
ring 占用率、drop-oldest 计数 |
/api/diagnostics/pipeline |
| Evaluate |
eval_ok / eval_skip |
pipeline counter |
| Decide |
matched / rate_limited |
pipeline counter |
| Execute |
control/stream/store 分布 |
pipeline counter |
| Feedback |
bblot 队列深度、写入延迟 |
feedback metrics |
§13 验收标准
13.1 架构验收
| # |
标准 |
| A1 |
嵌入式新业务配置仅 pipeline_rules + point_bindings(bbolt) |
| A2 |
热路径以 Trigger + PointCache + RuleTable 为核心;无 ExecutionIntent |
| A3 |
单 goroutine Pipeline;无 worker pool / Intent 队列 |
| A4 |
规则 init 预展开;热路径 无 expr |
| A5 |
Feedback 仅 bblot + last_state;禁止 Intent 回写 |
| A6 |
主链固定五段内联;不新增架构层 |
| A7 |
与 V2.1 包路径隔离;embedded build tag 可独立编译 |
13.2 功能验收
| # |
标准 |
| F1 |
阈值告警:eval → decide → control/stream;last_state 更新 |
| F2 |
公式派生:init 编译公式槽;UI 可见 PointCache |
| F3 |
频率:allow() dedup + RuleSlot minInterval 生效 |
| F4 |
bblot 含 source_idx/action_idx;重启不丢 |
| F5 |
control WritePoint 失败可 counter 统计;不阻塞 Pipeline |
| F6 |
ring buffer 满 drop-oldest,ScanEngine 不阻塞 |
13.3 性能验收
| 指标 |
标准 |
| Pipeline 热路径 |
零堆分配(go test -memprofile) |
| 控制延迟 P95 |
≤ 20ms(不含协议 IO) |
| 72h soak |
内存稳定;GC STW ≤ 5ms |
| Ring buffer |
满时 drop-oldest,采集 lag 不恶化 |
13.4 废弃验收(embedded profile)
EdgeRule expr 热路径 deprecated · ECM worker pool 非 embedded 默认 · DataPipeline map 缓冲替换 · SnapshotEvent / ExecutionIntent 不在 embedded 编译。
§14 实施分期
| 阶段 |
时间 |
交付 |
| M1 |
2026 Q3 |
P0:Pipeline Worker 骨架 + ScanEngine 对接 + 5 条样例 |
| M2 |
2026 Q4 |
P1:Rule 编译器 + ARM benchmark + 72h soak |
| M3 |
2027 Q1 |
P2:诊断 API + 精简 UI |
| M4 |
2027 Q2 |
P3:embedded 默认切换 + ECM gateway-only |
§15 V2.1 vs V2.2 总览
| 维度 |
V2.2 PRIMARY(Embedded) |
V2.1 可选(Gateway Rich Profile) |
| 部署默认 |
ARMv7 / RK3588 / PLC 边缘 |
边缘网关 / Edge Server |
| 内存 |
256MB–2GB |
多 GB 可接受 |
| 控制延迟 |
5–20ms |
50–200ms |
| 架构 |
五段 inline Pipeline |
六段 Intent 闭环 |
| 执行因 |
Trigger(栈) |
ExecutionIntent(堆) |
| 数据 |
PointCache |
SnapshotEvent + 扇出 |
| 决策 |
init 预展开 |
Decision Gate |
| Step Types |
3(control/stream/store) |
7 |
| Feedback |
bblot + last_state |
SES → Intent Core 闭环 |
| 详见 |
本文 §0–§15 |
附录 A |
┌─────────────────────────────────┐
│ EdgeX 边缘计算产品愿景 │
└──────────────┬──────────────────┘
│
┌────────────────────┴────────────────────┐
▼ ▼
┌─────────────────────┐ ┌─────────────────────┐
│ V2.2 PRIMARY │ │ V2.1 可选附录 │
│ Pipeline Worker │ │ Gateway Rich │
│ Trigger / PointCache│ │ ExecutionIntent │
│ inline 五段 │ │ 六段 Intent 闭环 │
└─────────────────────┘ └─────────────────────┘
│ │
RK3588 / ARMv7 控制盒(默认) 富网关 / 复杂联动(可选)
附录 A:V2.1 Gateway Rich Profile(可选)
定位:面向边缘网关、Edge Server、SaaS Edge 的富配置、可诊断、多步联动部署形态。非 EdgeX 工业嵌入式默认路径。与 V2.2 共享 ScanEngine 与 bbolt 配置基线,运行时架构不同。
A.1 六段式闭环主链
① Source Intake
② Snapshot Engine(window_ms / dedup_key / drop_policy)
③ Intent Core(Virtual / Window / SES 内部能力 → ExecutionIntent)
④ Decision Gate(Routing + Guards:rate_limit / min_interval)
⑤ Execution Runtime(七种 Step Types)
⑥ Feedback Loop(SES / Virtual 回写 → Intent Core)
A.2 三大核心实体(Gateway 专用)
- ExecutionIntent — 单一执行因(堆对象,含 Points map)
- ExecutionContext — 执行载体(瘦身;Trace/Rollback 独立)
- SnapshotEvent — 稳定输入(扇出多消费者)
A.3 Step Types(七种)
stream · control · storage · delay · check · rollback · ses_sync
A.4 Gateway 四条铁律
- 单一执行因:1 Snapshot → 1 Intent → 1 ExecutionContext
- 决策不能执行:Routing / Guard / Intent Core 不执行动作
- 执行不能解释:Runtime 只跑 Step Types
- 反馈必须回写控制面:Feedback → SES → Intent Core
A.5 Gateway Go 包结构
internal/snapshot/ · intent/ · decision/ · execution/ · feedback/
model/snapshot.go · intent.go · context.go
build tag: gateway
A.6 Gateway 实施任务(独立 P0–P3)
| ID |
任务 |
| GW-P0-1 |
Snapshot Engine · internal/snapshot/engine.go |
| GW-P0-2 |
Intent Core + Composer |
| GW-P0-3 |
Decision Gate(Routing + Guards) |
| GW-P0-4 |
Execution Runtime + Feedback 闭环 |
| GW-P1 |
EdgeRule → Intent/Mapping 迁移工具 |
| GW-P2 |
Mapping 管理 UI · Intent 诊断 |
| GW-P3 |
expr 主路径废弃 |
Gateway 验收标准、Intent Lifecycle、性能目标(Snapshot P95 ≤ 350ms 等)见历史 V2.1 文档归档;新嵌入式交付不阻塞 Gateway 路线。
A.7 选用指南
| 场景 |
选用 |
| RK3588 / ARMv7 控制盒 / PLC 边缘 / < 20ms 控制 |
V2.2 PRIMARY |
| 多协议汇聚 / 多步 Rollback / SES 闩锁闭环 |
V2.1 Gateway |
| Edge Server / 规则可视化 / Mapping UI |
V2.1 Gateway |
| 同一产品双部署 |
build tag embedded + gateway |
附录:交叉引用
| *维护:架构组 |
下次审查:P0-1 Pipeline Worker 首 PR 合并时* |