Phase 16.2.1: Performance optimization success - 26x speedup (20.46 MB/s)
修改内容: - 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:
@@ -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大文件传输)
|
||||
// 最多轮询5000次(50秒),如果持续无数据,检查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次poll(30s)无数据
|
||||
// ⭐⭐⭐⭐⭐ Phase 16.2.1优化:增加stdin超时机制(支持大文件传输)
|
||||
// 如果stdin未关闭,且超过300次poll(30s)无数据
|
||||
// 强制关闭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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user