Skip to content
Snippets Groups Projects
Commit 4f34f7ce authored by eta's avatar eta
Browse files

Merge branch 'ticket_391' into 'main'

arti-bench: don't allocate a separate receive-buffer for each job

Closes #391

See merge request tpo/core/arti!395
parents 3425a6cb 26bdbc4b
No related branches found
No related tags found
No related merge requests found
...@@ -149,11 +149,17 @@ impl TimingSummary { ...@@ -149,11 +149,17 @@ impl TimingSummary {
} }
} }
/// How much should we be willing to read at a time?
const RECV_BUF_LEN: usize = 8192;
/// Run the timing routine /// Run the timing routine
fn run_timing(mut stream: TcpStream, send: &Arc<[u8]>, receive: &Arc<[u8]>) -> Result<()> { fn run_timing(mut stream: TcpStream, send: &Arc<[u8]>, receive: &Arc<[u8]>) -> Result<()> {
let peer_addr = stream.peer_addr()?; let peer_addr = stream.peer_addr()?;
// Do this potentially costly allocation before we do all the timing stuff. let mut received = vec![0_u8; RECV_BUF_LEN];
let mut received = vec![0_u8; receive.len()]; let expected_len = receive.len();
let mut expected = receive.deref();
let mut mismatch = false;
let mut total_read = 0;
info!("Accepted connection from {}", peer_addr); info!("Accepted connection from {}", peer_addr);
let accepted_ts = SystemTime::now(); let accepted_ts = SystemTime::now();
...@@ -168,15 +174,26 @@ fn run_timing(mut stream: TcpStream, send: &Arc<[u8]>, receive: &Arc<[u8]>) -> R ...@@ -168,15 +174,26 @@ fn run_timing(mut stream: TcpStream, send: &Arc<[u8]>, receive: &Arc<[u8]>) -> R
panic!("unexpected EOF"); panic!("unexpected EOF");
} }
let first_byte_ts = SystemTime::now(); let first_byte_ts = SystemTime::now();
stream.read_exact(&mut received[read..])?; if received[0..read] != expected[0..read] {
mismatch = true;
}
expected = &expected[read..];
total_read += read;
while total_read < expected_len {
let read = stream.read(&mut received)?;
if read == 0 {
panic!("unexpected eof");
}
if received[0..read] != expected[0..read] {
mismatch = true;
}
expected = &expected[read..];
total_read += read;
}
let read_done_ts = SystemTime::now(); let read_done_ts = SystemTime::now();
info!( info!("Received {} bytes payload from {}.", total_read, peer_addr);
"Received {} bytes payload from {}.",
received.len(),
peer_addr
);
// Check we actually got what we thought we would get. // Check we actually got what we thought we would get.
if received != receive.deref() { if mismatch {
panic!("Received data doesn't match expected; potential corruption?"); panic!("Received data doesn't match expected; potential corruption?");
} }
let st = ServerTiming { let st = ServerTiming {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment