perf(ri-llm-provider): reduce idle memory usage (O-04 + lint fixes)#5
Open
endless-bot wants to merge 2 commits into
Open
perf(ri-llm-provider): reduce idle memory usage (O-04 + lint fixes)#5endless-bot wants to merge 2 commits into
endless-bot wants to merge 2 commits into
Conversation
…client endless-ri-runner is single-task (ToolExecutionMode::Sequential), so more than 1 idle connection per host provides no throughput benefit and wastes socket buffer memory (~32-64 KB/conn). pool_idle_timeout(50s) already cleans up stale connections; this change caps the maximum idle footprint at any single moment to 1 connection per host. Active (in-flight) connections are not affected by this limit. Co-authored-by: 员外 (Jiang Guimin) <guimin.jiang@longbridge-inc.com>
- Auto-fix collapsible_if, unnecessary_cast, redundant_closure, if_let_instead_of_match, manual_is_multiple_of via cargo clippy --fix - Add #[allow(clippy::too_many_arguments)] to functions with >7 args (sign_aws_sigv4_headers, stream_* internal fns, retry delay fns) - Add #[allow(clippy::large_enum_variant)] to FauxResponseStep enum - Add #[allow(clippy::field_reassign_with_default)] to build_anthropic_simple_payload_for_client (conditional field assignment pattern cannot be restructured without behavioural changes) - Remove redundant ..Default::default() in GooglePayloadOptions and MistralPayloadOptions struct literals (all fields already specified) No functional changes; cargo test -p ri-llm-provider passes (5/5). Co-authored-by: 员外 (Jiang Guimin) <guimin.jiang@longbridge-inc.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: ri Worker Agent 进程内存优化
概述
将
endless-ri-runner进程在 idle 状态下的内存占用从约 17–20 MB 降低至目标 < 10 MB,通过 3 项独立优化实现:current_thread(消除 CPU 核数量的 worker 线程)pool_max_idle_per_host(1),限制空闲连接数)改动说明
endless-ri-runner.rs— tokio current_thread + mimalloc为什么安全:
endless-ri-runner使用ToolExecutionMode::Sequential,无并发工具调用。所有 I/O 均使用tokio::fs/tokio::process(全异步),不存在spawn_blocking。切换current_thread后行为与multi_thread完全一致,消除了每 CPU 核一个 worker 线程的内存开销(8 核机器节省约 4–8 MB RSS)。node_http_proxy.rs— 连接池收紧为什么安全:
pool_max_idle_per_host(1)仅限制空闲连接数,活跃(in-flight)连接不受影响。单任务进程无并发 LLM 请求,1 个空闲连接足以支持连接复用。测试
code/endless:cargo test -p endless-mcp-ri— 82 tests passed (0 failed)code/ri:cargo test -p ri-llm-provider --lib -- node_http_proxy— 3 tests passed (0 failed)预期收益
目标:idle 30s 后 VmRSS 中位数 < 10 MB(从约 17–20 MB 降低)。
回滚
每个优化可独立
git revert回滚,无数据库迁移,无 API 变更,零风险回滚。