3. 核心结构体定义
3.1 采集通信上下文
管理单条连接的生命周期与状态。
type CollectCommContext struct {
RTTBuffer []RTTNode // RTT 统计环缓冲
RTTIndex int // 环缓冲当前索引
MTUState *MTUFSM // MTU 协商状态机
BatchRead *BatchReadSnapshot // Gap 合并策略快照
LastActivity time.Time // 最后活跃时间 (业务通信成功时刻)
Stats CommStats // 统计信息
Config ProtocolConfig // 协议配置 (含 Heartbeat, BufferSize 等)
}
type ProtocolConfig struct {
HeartbeatInterval int
BufferSize int
Qos int
Interval int
}
3.2 RTT 统计节点
用于计算单次通信质量。
type RTTNode struct {
SeqNo uint16 // 序列号
SendTS time.Time // 发送时间戳
RecvTS time.Time // 接收时间戳
AckStatus bool // 是否收到 ACK
RTT int64 // 计算出的 RTT (us)
}
3.3 MTU 协商记录
记录 MTU 探测历史,辅助状态机决策。
type MTUNegotiationRecord struct {
AttemptValue int // 尝试值
ResponseTime int64 // 耗时 (us)
RetryCount int // 重试次数
Success bool // 结果
Timestamp time.Time // 记录时间
}
3.4 Batch Read 快照
记录当前 Gap 合并策略的运行状态。
type BatchReadSnapshot struct {
CurrentGap int // 当前生效的 Gap 值
MaxGap int // 允许的最大 Gap (受 MTU 限制)
MergedRequests uint64 // 合并后的请求总数
SavedRequests uint64 // 节省的请求数量 (原请求数 - 合并后请求数)
FillEfficiency float64 // 填充效率 (有效数据 / 总请求数据)
}