perf: 消息内存按字节预算,杜绝大报文流撑爆内存

- 新增 MessageRing:条数上限 + 每连接 32MB 字节预算双重驱逐
  (从最旧丢弃,均摊 O(1));预分配容量按设置钳制在 512
- 单条 payload 保留上限 256KB → 128KB;MqttRecord::retained_bytes
  计入文本与原始字节,供预算驱逐与资源监控展示
- 清空消息统一走 clear_messages;设置页标注字节预算兜底说明
- 新增单元测试:条数驱逐、字节预算、超预算单条保留、驱逐顺序
This commit is contained in:
2026-09-29 17:00:34 +08:00
parent b862a50b04
commit 85a3bfcb1b
4 changed files with 164 additions and 17 deletions
+10 -1
View File
@@ -17,7 +17,7 @@ use gpui_kit::{
Styled as _, Window,
};
use crate::model::{AppSettings, ThemeModePref};
use crate::model::{AppSettings, ThemeModePref, MAX_CONNECTION_MESSAGE_BYTES};
use crate::mqtt::MqttEngine;
use crate::ui::app::MqttXApp;
use crate::ui::widgets::{field, make_select, OptionDelegate};
@@ -388,6 +388,15 @@ impl Render for SettingsDialog {
"每条连接内存中保留的消息条数(100~100000)",
Input::new(&self.max_messages),
))
.child(
div()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child(format!(
"另有每连接 {}MB 的字节预算兜底:大报文流会优先按字节从最旧开始驱逐",
MAX_CONNECTION_MESSAGE_BYTES / (1024 * 1024)
)),
)
.child(
h_flex()
.justify_between()