Skip to content

Commit

Permalink
Increase transport TxBuffer::BUFFER_SIZE to 1MiB
Browse files Browse the repository at this point in the history
Add static const methods to get send and receive buffer sizes. This is
useful for testing in http3 crate, for example.

Alter tests in http3 and transport crates to not assume a given buffer
size.
  • Loading branch information
Andy Grover committed Jul 8, 2020
1 parent 7b6e1e4 commit 15f39d3
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 61 deletions.
104 changes: 77 additions & 27 deletions neqo-http3/src/connection_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ mod tests {
if let ConnectionEvent::RecvStreamReadable { stream_id } = e {
if stream_id == request_stream_id {
// Read the DATA frame.
let mut buf = [1_u8; 0xffff];
let mut buf = [1_u8; Connection::stream_recv_buffer_size()];
let (amount, fin) = server.conn.stream_recv(stream_id, &mut buf).unwrap();
assert_eq!(fin, true);
assert_eq!(
Expand Down Expand Up @@ -1924,15 +1924,19 @@ mod tests {
assert_eq!(sent, Ok(first_frame.len()));

// The second frame cannot fit.
let sent = client.send_request_body(request_stream_id, &[0_u8; 0xffff]);
let sent = client.send_request_body(
request_stream_id,
&[0_u8; Connection::stream_recv_buffer_size()],
);
assert_eq!(sent, Ok(expected_second_data_frame.len()));

// Close stream.
let _ = client.stream_close_send(request_stream_id);

let mut out = client.process(None, now());
// We need to loop a bit until all data has been sent.
for _i in 0..55 {
// We need to loop a bit until all data has been sent. Once for every 1K
// of data.
for _i in 0..Connection::stream_send_buffer_size() / 1000 {
out = server.conn.process(out.dgram(), now());
out = client.process(out.dgram(), now());
}
Expand All @@ -1942,7 +1946,7 @@ mod tests {
if let ConnectionEvent::RecvStreamReadable { stream_id } = e {
if stream_id == request_stream_id {
// Read DATA frames.
let mut buf = [1_u8; 0xffff];
let mut buf = [1_u8; Connection::stream_recv_buffer_size()];
let (amount, fin) = server.conn.stream_recv(stream_id, &mut buf).unwrap();
assert_eq!(fin, true);
assert_eq!(
Expand Down Expand Up @@ -1987,35 +1991,49 @@ mod tests {
// After the first frame there is exactly 63+2 bytes left in the send buffer.
#[test]
fn fetch_two_data_frame_second_63bytes() {
fetch_with_two_data_frames(
&[0_u8; 65447],
&[0x0, 0x80, 0x0, 0xff, 0x0a7],
&[0x0, 0x3f],
&[0_u8; 63],
);
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 88;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(&[0_u8; FIRST_FRAME_SIZE], &enc, &[0x0, 0x3f], &[0_u8; 63]);
}

// Send 2 frames. For the second one we can only send 63 bytes.
// After the first frame there is exactly 63+3 bytes left in the send buffer,
// but we can only send 63 bytes.
#[test]
fn fetch_two_data_frame_second_63bytes_place_for_66() {
fetch_with_two_data_frames(
&[0_u8; 65446],
&[0x0, 0x80, 0x0, 0xff, 0x0a6],
&[0x0, 0x3f],
&[0_u8; 63],
);
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 89;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(&[0_u8; FIRST_FRAME_SIZE], &enc, &[0x0, 0x3f], &[0_u8; 63]);
}

// Send 2 frames. For the second one we can only send 64 bytes.
// After the first frame there is exactly 64+3 bytes left in the send buffer,
// but we can only send 64 bytes.
#[test]
fn fetch_two_data_frame_second_64bytes_place_for_67() {
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 90;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(
&[0_u8; 65445],
&[0x0, 0x80, 0x0, 0xff, 0x0a5],
&[0_u8; FIRST_FRAME_SIZE],
&enc,
&[0x0, 0x40, 0x40],
&[0_u8; 64],
);
Expand All @@ -2025,9 +2043,17 @@ mod tests {
// After the first frame there is exactly 16383+3 bytes left in the send buffer.
#[test]
fn fetch_two_data_frame_second_16383bytes() {
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 16409;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(
&[0_u8; 49126],
&[0x0, 0x80, 0x0, 0xbf, 0x0e6],
&[0_u8; FIRST_FRAME_SIZE],
&enc,
&[0x0, 0x7f, 0xff],
&[0_u8; 16383],
);
Expand All @@ -2037,9 +2063,17 @@ mod tests {
// After the first frame there is exactly 16383+4 bytes left in the send buffer, but we can only send 16383 bytes.
#[test]
fn fetch_two_data_frame_second_16383bytes_place_for_16387() {
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 16410;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(
&[0_u8; 49125],
&[0x0, 0x80, 0x0, 0xbf, 0x0e5],
&[0_u8; FIRST_FRAME_SIZE],
&enc,
&[0x0, 0x7f, 0xff],
&[0_u8; 16383],
);
Expand All @@ -2049,9 +2083,17 @@ mod tests {
// After the first frame there is exactly 16383+5 bytes left in the send buffer, but we can only send 16383 bytes.
#[test]
fn fetch_two_data_frame_second_16383bytes_place_for_16388() {
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 16411;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(
&[0_u8; 49124],
&[0x0, 0x80, 0x0, 0xbf, 0x0e4],
&[0_u8; FIRST_FRAME_SIZE],
&enc,
&[0x0, 0x7f, 0xff],
&[0_u8; 16383],
);
Expand All @@ -2061,9 +2103,17 @@ mod tests {
// After the first frame there is exactly 16384+5 bytes left in the send buffer, but we can send 16384 bytes.
#[test]
fn fetch_two_data_frame_second_16384bytes_place_for_16389() {
const FIRST_FRAME_SIZE: usize = Connection::stream_send_buffer_size() - 16412;

let data_frame = HFrame::Data {
len: FIRST_FRAME_SIZE as u64,
};
let mut enc = Encoder::default();
data_frame.encode(&mut enc);

fetch_with_two_data_frames(
&[0_u8; 49123],
&[0x0, 0x80, 0x0, 0xbf, 0x0e3],
&[0_u8; FIRST_FRAME_SIZE],
&enc,
&[0x0, 0x80, 0x0, 0x40, 0x0],
&[0_u8; 16384],
);
Expand Down
27 changes: 24 additions & 3 deletions neqo-transport/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::path::Path;
use crate::qlog;
use crate::recovery::{LossRecovery, RecoveryToken, SendProfile, GRANULARITY};
use crate::recv_stream::{RecvStream, RecvStreams, RX_STREAM_DATA_WINDOW};
use crate::send_stream::{SendStream, SendStreams};
use crate::send_stream::{SendStream, SendStreams, TxBuffer};
use crate::stats::Stats;
use crate::stream_id::{StreamId, StreamIndex, StreamIndexes};
use crate::tparams::{
Expand Down Expand Up @@ -2568,6 +2568,16 @@ impl Connection {
Ok(())
}

/// The per-stream send buffer size.
pub const fn stream_send_buffer_size() -> usize {
TxBuffer::BUFFER_SIZE
}

/// The per-stream receive max data size.
pub const fn stream_recv_buffer_size() -> usize {
RX_STREAM_DATA_WINDOW as usize
}

/// Get all current events. Best used just in debug/testing code, use
/// next_event() instead.
pub fn events(&mut self) -> impl Iterator<Item = ConnectionEvent> {
Expand Down Expand Up @@ -3586,13 +3596,24 @@ mod tests {
// no event because still limited by conn max data
assert_eq!(client.events().count(), 0);

// increase max data
// Increase max data. Avail space now limited by stream credit
client.handle_max_data(100_000_000);
// Avail space now limited by tx buffer
assert_eq!(
client.stream_avail_send_space(stream_id).unwrap(),
TxBuffer::BUFFER_SIZE - SMALL_MAX_DATA
);

// Increase max stream data. Avail space now limited by tx buffer
client
.send_streams
.get_mut(stream_id.into())
.unwrap()
.set_max_stream_data(100_000_000);
assert_eq!(
client.stream_avail_send_space(stream_id).unwrap(),
TxBuffer::BUFFER_SIZE - SMALL_MAX_DATA + 4096
);

let evts = client.events().collect::<Vec<_>>();
assert_eq!(evts.len(), 1);
assert!(matches!(evts[0], ConnectionEvent::SendStreamWritable{..}));
Expand Down
Loading

0 comments on commit 15f39d3

Please sign in to comment.