Skip to content

Commit 9f8ed57

Browse files
committed
perf: raise server MAX_READ_SIZE to SFTP standard 255 KiB
The bssh-server hard-capped every SFTP `READ` reply at 64 KiB (`MAX_READ_SIZE = 65536`) regardless of what the client requested. `bssh-russh-sftp` and OpenSSH's `sftp-server` both use the SFTP standard `MAX_READ_LENGTH = 261120` (255 KiB) for request sizing, so a client asking for a 256 KiB chunk only ever got 64 KiB back, forcing it to issue four extra requests for the same byte stream. Bump `MAX_READ_SIZE` to `261120` so server replies match the standard chunk size used by the rest of the stack. Combined with client-side pipelining (#196), this directly cuts the per-MiB request count on downloads from 16 → 4. Memory exposure stays bounded: handles are still capped at `MAX_HANDLES = 1000` per session and each in-flight read still uses a single per-request buffer of this size (max ~255 KiB × in-flight requests).
1 parent 27d20e4 commit 9f8ed57

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/server/sftp.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,15 @@ struct DirEntryInfo {
164164
/// Maximum number of open handles per session to prevent resource exhaustion.
165165
const MAX_HANDLES: usize = 1000;
166166

167-
/// Maximum read buffer size (64KB) to prevent memory exhaustion.
168-
const MAX_READ_SIZE: u32 = 65536;
167+
/// Maximum read buffer size per request. Matches the SFTP standard
168+
/// `MAX_READ_LENGTH` (255 KiB) used by `bssh-russh-sftp` and OpenSSH
169+
/// `sftp-server`. The previous 64 KiB cap silently truncated client `READ`
170+
/// requests for 256 KiB chunks down to 64 KiB, multiplying request count 4×
171+
/// for the same byte stream and dragging down sustained download throughput.
172+
/// Memory exposure remains bounded because handles are capped at
173+
/// [`MAX_HANDLES`] per session and each in-flight read uses a single
174+
/// per-request buffer of this size.
175+
const MAX_READ_SIZE: u32 = 261120;
169176

170177
/// Normalize a path's `..` and `.` components without touching the filesystem.
171178
///

0 commit comments

Comments
 (0)