-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba989a8
commit b534f0f
Showing
10 changed files
with
781 additions
and
249 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use criterion::criterion_main; | ||
|
||
mod benchmarks; | ||
|
||
criterion_main! { | ||
benchmarks::tokio_concurrent::tokio, | ||
// benchmarks::external_process::benches, | ||
// benchmarks::iter_with_large_drop::benches, | ||
// benchmarks::iter_with_large_setup::benches, | ||
// benchmarks::iter_with_setup::benches, | ||
// benchmarks::with_inputs::benches, | ||
// benchmarks::special_characters::benches, | ||
// benchmarks::measurement_overhead::benches, | ||
// benchmarks::custom_measurement::benches, | ||
// benchmarks::sampling_mode::benches, | ||
// benchmarks::async_measurement_overhead::benches, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use bytes::{Bytes, BytesMut, BufMut}; | ||
use mqrstt::packets::{Packet, ConnAck, ConnAckFlags, Publish, Disconnect}; | ||
|
||
pub mod tokio_concurrent; | ||
|
||
|
||
fn fill_stuff(buffer: &mut BytesMut, publ_count: usize, publ_size: usize) { | ||
empty_connect(buffer); | ||
for i in 0..publ_count{ | ||
very_large_publish(i as u16, publ_size/5).write(buffer).unwrap(); | ||
} | ||
empty_disconnect().write(buffer).unwrap(); | ||
} | ||
|
||
fn empty_disconnect() -> Packet{ | ||
let discon = Disconnect{ | ||
reason_code: mqrstt::packets::reason_codes::DisconnectReasonCode::ServerBusy, | ||
properties: Default::default(), | ||
}; | ||
|
||
Packet::Disconnect(discon) | ||
} | ||
|
||
fn empty_connect(buffer: &mut BytesMut){ | ||
// let conn_ack = ConnAck{ | ||
// connack_flags: ConnAckFlags::default(), | ||
// reason_code: mqrstt::packets::reason_codes::ConnAckReasonCode::Success, | ||
// connack_properties: Default::default(), | ||
// }; | ||
|
||
// Packet::ConnAck(conn_ack) | ||
// buffer.put_u8(0b0010_0000); // Connack flags | ||
// buffer.put_u8(0x01); // Connack flags | ||
// buffer.put_u8(0x00); // Reason code, | ||
// buffer.put_u8(0x00); // empty properties | ||
|
||
buffer.put_u8(0x20); | ||
buffer.put_u8(0x13); | ||
buffer.put_u8(0x00); | ||
buffer.put_u8(0x00); | ||
buffer.put_u8(0x10); | ||
buffer.put_u8(0x27); | ||
buffer.put_u8(0x06); | ||
buffer.put_u8(0x40); | ||
buffer.put_u8(0x00); | ||
buffer.put_u8(0x00); | ||
buffer.put_u8(0x25); | ||
buffer.put_u8(0x01); | ||
buffer.put_u8(0x2a); | ||
buffer.put_u8(0x01); | ||
buffer.put_u8(0x29); | ||
buffer.put_u8(0x01); | ||
buffer.put_u8(0x22); | ||
buffer.put_u8(0xff); | ||
buffer.put_u8(0xff); | ||
buffer.put_u8(0x28); | ||
buffer.put_u8(0x01); | ||
|
||
|
||
} | ||
|
||
|
||
/// Returns Publish Packet with 5x `repeat` as payload in bytes. | ||
fn very_large_publish(id: u16, repeat: usize) -> Packet { | ||
let publ = Publish{ | ||
dup: false, | ||
qos: mqrstt::packets::QoS::ExactlyOnce, | ||
retain: false, | ||
topic: "BlaBla".to_string(), | ||
packet_identifier: Some(id), | ||
publish_properties: Default::default(), | ||
payload: Bytes::from_iter([0u8, 1u8, 2, 3, 4].repeat(repeat)), | ||
}; | ||
|
||
Packet::Publish(publ) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use std::{io::{Write, Cursor}, hint::black_box, time::Duration}; | ||
|
||
use bytes::BytesMut; | ||
use criterion::{criterion_group, BatchSize, Criterion}; | ||
use mqrstt::{new_tokio, ConnectOptions}; | ||
|
||
use super::fill_stuff; | ||
|
||
struct ReadWriteTester<'a>{ | ||
read: Cursor<&'a [u8]>, | ||
write: Vec<u8> | ||
} | ||
|
||
impl<'a> ReadWriteTester<'a> { | ||
pub fn new(read: &'a [u8]) -> Self { | ||
Self{ | ||
read: Cursor::new(read), | ||
write: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> tokio::io::AsyncRead for ReadWriteTester<'a> { | ||
fn poll_read( | ||
mut self: std::pin::Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
buf: &mut tokio::io::ReadBuf<'_>, | ||
) -> std::task::Poll<std::io::Result<()>> { | ||
tokio::io::AsyncRead::poll_read(std::pin::Pin::new(&mut self.read), cx, buf) | ||
} | ||
} | ||
|
||
impl<'a> tokio::io::AsyncWrite for ReadWriteTester<'a> { | ||
fn poll_write( | ||
self: std::pin::Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
buf: &[u8], | ||
) -> std::task::Poll<Result<usize, std::io::Error>> { | ||
todo!() | ||
} | ||
|
||
fn poll_flush(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), std::io::Error>> { | ||
todo!() | ||
} | ||
|
||
fn poll_shutdown(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), std::io::Error>> { | ||
todo!() | ||
} | ||
} | ||
|
||
|
||
fn tokio_concurrent(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Tokio concurrent throughput test"); | ||
group.sample_size(10); | ||
group.measurement_time(Duration::from_secs(20)); | ||
|
||
group.bench_function("tokio_bench_concurrent_read_write", |b| { | ||
let runtime = tokio::runtime::Runtime::new().unwrap(); | ||
b.to_async(runtime) | ||
.iter_with_setup( | ||
|| { | ||
let mut buffer = BytesMut::new(); | ||
|
||
// :0 tells the OS to pick an open port. | ||
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let addr = listener.local_addr().unwrap(); | ||
|
||
let tcp_stream = std::net::TcpStream::connect(addr).unwrap(); | ||
|
||
let (mut server, _addr) = listener.accept().unwrap(); | ||
|
||
fill_stuff(&mut buffer, 100, 5_000_000); | ||
|
||
server.write_all(&buffer.to_vec()).unwrap(); | ||
|
||
let tcp_stream = tokio::net::TcpStream::from_std(tcp_stream).unwrap(); | ||
(tcp_stream, server, _addr) | ||
}, | ||
|(tcp_stream, server, addr)| async move { | ||
|
||
let _server_box = black_box(server); | ||
let _addr = black_box(addr); | ||
|
||
let options = ConnectOptions::new("test", true); | ||
let (mut network, _) = new_tokio(options); | ||
|
||
network.connect(tcp_stream, ()).await.unwrap(); | ||
|
||
network.run().await.unwrap(); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(tokio, tokio_concurrent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.