Skip to content

Commit 63b7955

Browse files
milankinenclaude
andcommitted
Extract shared RELAY_CHUNK_SIZE constant
Four TCP/Unix byte-relay loops (rpc_bridge, host_socket_forward, two in cli tcp relay) all hard-coded the same 8 KB read buffer. Move it to airlock_common::RELAY_CHUNK_SIZE so the chunk size stays symmetric on both ends of the RPC if we tune it. Measurement showed no throughput benefit from bumping to 64 KB — kernel-side TCP batching already coalesces bytes upstream of our relay. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5e05328 commit 63b7955

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

app/airlock-cli/src/network/tcp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub async fn connect_server(addr: &str) -> anyhow::Result<io::Transport> {
4646
/// When either direction closes, both sides are fully shut down.
4747
pub async fn relay(mut container: io::Transport, mut server: io::Transport) {
4848
let c2s = async {
49-
let mut buf = [0u8; 8192];
49+
let mut buf = vec![0u8; airlock_common::RELAY_CHUNK_SIZE];
5050
loop {
5151
match container.read.read(&mut buf).await {
5252
Ok(0) | Err(_) => break,
@@ -60,7 +60,7 @@ pub async fn relay(mut container: io::Transport, mut server: io::Transport) {
6060
};
6161

6262
let s2c = async {
63-
let mut buf = [0u8; 8192];
63+
let mut buf = vec![0u8; airlock_common::RELAY_CHUNK_SIZE];
6464
loop {
6565
match server.read.read(&mut buf).await {
6666
Ok(0) | Err(_) => break,

app/airlock-common/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@ pub const NETWORK_PORT: u32 = 1025;
4040
/// Filename of the Unix domain socket that `airlock go` creates on the host so
4141
/// that `airlock exec` can attach sidecar processes to the running container.
4242
pub const CLI_SOCK_FILENAME: &str = "cli.sock";
43+
44+
/// Read-buffer size used by every TCP/Unix relay loop that pushes bytes
45+
/// into a `TcpSink.send` call. Bigger chunks mean fewer capnp messages
46+
/// (less framing overhead) but do not measurably improve throughput
47+
/// beyond this value in practice — TCP batching in the guest and
48+
/// host kernels already coalesces bytes before they reach a relay.
49+
pub const RELAY_CHUNK_SIZE: usize = 8 * 1024;

app/airlockd/src/net/host_socket_forward.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async fn relay(
112112
// Bidirectional relay: local ↔ RPC.
113113
// When either direction closes, clean up both sides.
114114
let local_to_rpc = async {
115-
let mut buf = [0u8; 8192];
115+
let mut buf = vec![0u8; airlock_common::RELAY_CHUNK_SIZE];
116116
loop {
117117
match local_read.read(&mut buf).await {
118118
Ok(0) | Err(_) => break,

app/airlockd/src/net/rpc_bridge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub async fn relay(
9090
remote_rx: &mut mpsc::Receiver<Bytes>,
9191
) {
9292
let to_remote = async {
93-
let mut buf = [0u8; 8192];
93+
let mut buf = vec![0u8; airlock_common::RELAY_CHUNK_SIZE];
9494
loop {
9595
match local_read.read(&mut buf).await {
9696
Ok(0) => break,

0 commit comments

Comments
 (0)