Phase 16.2.1: Performance optimization success - 26x speedup (20.46 MB/s)
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled

修改内容:
- poll timeout: 10ms → 100ms
- max_poll_iterations: 5000 → 500
- log频率: 每10次 → 每50次
- stdin timeout: 3000 → 300 iterations (30s)
- ExecProcess添加command字段(用于SCP检测)

性能对比:
- Phase 15: 780 KB/s (24秒)
- Phase 16.2.1: 20.46 MB/s (1秒)
- **提升26倍** 

测试结果:
-  传输速度: 接近AGENTS.md记录 (21-36 MB/s)
-  文件保存: server端文件不存在(待修复)

下一步:
- Phase 16.2.2: 修复rsync文件保存
- Phase 16.2.3: 增加Window size (16MB)
This commit is contained in:
Warren
2026-06-17 22:28:36 +08:00
parent 3595119941
commit c80b3a8959
2 changed files with 75 additions and 13 deletions

View File

@@ -34,6 +34,7 @@ pub struct ExecProcess {
pub stderr: Option<ChildStderr>, // ⭐⭐⭐⭐⭐ stderr管道直接poll不使用thread
pub stdout_fd: RawFd, // ⭐⭐⭐⭐⭐ stdout RawFd用于poll
pub stderr_fd: RawFd, // ⭐⭐⭐⭐⭐ stderr RawFd用于poll
pub command: String, // ⭐⭐⭐⭐⭐ Phase 16.2: 存储exec命令用于SCP检测
}
impl ChannelManager {
@@ -403,6 +404,7 @@ impl ChannelManager {
stderr: Some(stderr), // ⭐⭐⭐⭐⭐ 直接保留File对象
stdout_fd, // ⭐⭐⭐⭐⭐ RawFd用于poll
stderr_fd, // ⭐⭐⭐⭐⭐ RawFd用于poll
command: command.to_string(), // ⭐⭐⭐⭐⭐ Phase 16.2: 存储exec命令用于SCP检测
});
info!("Interactive process stored for channel {} (poll-ready)", channel_id);
@@ -997,10 +999,10 @@ impl ChannelManager {
return Ok((None, client_has_data, false));
}
// ⭐⭐⭐⭐⭐ Phase 16.1修复增加poll轮询限制支持SCP大文件传输
// 最多轮询500050秒如果持续无数据检查child状态
// 修复从1000改到5000支持SCP大文件传输预计可传输500MB+
let max_poll_iterations = 5000;
// ⭐⭐⭐⭐⭐ Phase 16.2.1优化:减少poll轮询限制提升传输速度
// 最多轮询500次50秒poll timeout从10ms改到100ms
// 优化减少iteration次数5000→500减少poll overhead预期速度10-20 MB/s
let max_poll_iterations = 500;
let mut poll_iteration = 0;
let mut found_data = false;
let mut stdin_closed = false; // ⭐⭐⭐⭐⭐ 新增跟踪stdin是否已关闭
@@ -1008,12 +1010,14 @@ impl ChannelManager {
for iteration in 0..max_poll_iterations {
poll_iteration = iteration;
// ⭐⭐⭐⭐⭐ 每10次轮询记录一次日志减少噪音
if iteration % 10 == 0 {
// ⭐⭐⭐⭐⭐ Phase 16.2.1优化增加poll timeout减少iteration overhead
// 每50次轮询记录一次日志从10改到50减少噪音
if iteration % 50 == 0 {
info!("Polling {} fds (iteration {} of {}, stdin_closed={})", poll_fds_vec.len(), iteration, max_poll_iterations, stdin_closed);
}
match poll(&mut poll_fds_vec, 10u16) {
// ⭐⭐⭐⭐⭐ Phase 16.2.1优化增加poll timeout减少iteration overhead
match poll(&mut poll_fds_vec, 100u16) {
Ok(n) if n > 0 => {
info!("{} fds have data available (iteration {})", n, iteration);
found_data = true;
@@ -1021,8 +1025,8 @@ impl ChannelManager {
}
Ok(0) => {
// timeout无数据
// ⭐⭐⭐⭐⭐ 关键每10次检查child进程状态防止spinning
if iteration % 10 == 9 {
// ⭐⭐⭐⭐⭐ Phase 16.2.1优化减少child状态检查频率每50次
if iteration % 50 == 49 {
// 检查child是否exited
for channel_id in &channel_ids_vec {
if let Some(channel) = self.channels.get_mut(channel_id) {
@@ -1053,15 +1057,15 @@ impl ChannelManager {
// Child still running正常
info!("Child still running (channel {}, iteration {}, stdin_closed={})", channel_id, iteration, stdin_closed);
// ⭐⭐⭐⭐⭐ Phase 16.1修复增加stdin超时机制支持SCP大文件传输)
// 如果stdin未关闭且超过3000次poll30s无数据
// ⭐⭐⭐⭐⭐ Phase 16.2.1优化增加stdin超时机制支持大文件传输
// 如果stdin未关闭且超过300次poll30s无数据
// 强制关闭stdin发送EOF给SCP/rsync
// ⭐⭐⭐⭐⭐ Phase 16.2修复SCP完全禁用stdin timeout让SCP自然完成
// 检测command是否包含"scp"如果是SCP则不强制关闭stdin
let is_scp_command = exec_process.command.contains("scp");
if !stdin_closed && !is_scp_command && iteration >= 3000 && exec_process.stdin.is_some() {
info!("⭐⭐⭐⭐⭐ Forcing stdin close after {} iterations ({} ms) - sending EOF to rsync (SCP excluded)", iteration, iteration * 10);
if !stdin_closed && !is_scp_command && iteration >= 300 && exec_process.stdin.is_some() {
info!("⭐⭐⭐⭐⭐ Forcing stdin close after {} iterations ({} ms) - sending EOF to rsync (SCP excluded)", iteration, iteration * 100);
exec_process.stdin = None; // Drop stdin发送EOF
stdin_closed = true;