Skip to content

feat(relay): use 64 KiB buffers for the none cipher - #2198

Open
pylaterreur wants to merge 2 commits into
shadowsocks:masterfrom
pylaterreur:none-cipher-64k-buffer
Open

pylaterreur wants to merge 2 commits into
shadowsocks:masterfrom
pylaterreur:none-cipher-64k-buffer

Conversation

@pylaterreur

Copy link
Copy Markdown

The TCP relay of sslocal and ssserver reads in chunks of plain_read_buffer_size(): 16 KiB for the none method, while the AEAD-2022 methods already use 64 KiB (their MAX_PACKET_SIZE). none has no framing that would tie it to 16 KiB, so this PR uses 64 KiB for it too. On bulk transfers that means up to four times fewer read/write calls per byte.

Measured with sslocal (tunnel) → ssserver → target, method none, 2 GB per transfer, every transfer checked byte for byte, on loopback. The leg between sslocal and ssserver was plain TCP, then MPTCP (--tcp-multipath). Linux 6.17 on a Ryzen 9 5900X (8-vCPU VM), 5 rounds with the builds alternating within each round, medians. The machine was shared with other VMs (1-minute load 1.6 to 7.3, median 2.9), so throughput varies a lot between runs; the CPU per GB is steadier. CPU is the seconds per GB of each process, lower is better.

leg direction master this PR change
TCP upload sslocal CPU s/GB 1.48 0.92 −38 %
ssserver CPU s/GB 1.28 0.69 −46 %
throughput Gbit/s 5.40 8.51 +58 %
download sslocal CPU s/GB 1.95 0.91 −53 %
ssserver CPU s/GB 1.19 0.72 −39 %
throughput Gbit/s 4.47 8.10 +81 %
MPTCP upload sslocal CPU s/GB 2.71 1.51 −44 %
ssserver CPU s/GB 1.61 0.91 −44 %
throughput Gbit/s 3.00 5.46 +82 %
download sslocal CPU s/GB 1.96 0.96 −51 %
ssserver CPU s/GB 3.62 2.17 −40 %
throughput Gbit/s 1.87 2.75 +47 %

The cost is memory: the two relay buffers of a none connection grow from 2 × 16 KiB to 2 × 64 KiB, as for the 2022 methods. Nothing else changes; the other methods keep their sizes.

Context: OpenMPTCProuter offers none for its shadowsocks-rust proxy, and routers without AES instructions are CPU-bound with the other methods. A separate PR adds a splice(2) path on Linux for the same case; the two are independent.

Tests on Linux with Rust 1.99.0: cargo test of the workspace (default features) and of crates/shadowsocks (default and no features), and clippy with CI's flags. No new warnings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

The none cipher does not frame or encrypt anything, so there is no
reason to read in 16 KiB chunks. The AEAD 2022 ciphers already use
64 KiB; do the same here, which halves the syscalls per byte on large
transfers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant