mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_http_load_test: store connections in a slab::Slab
This commit is contained in:
parent
a2a2fa5807
commit
6691b77824
4 changed files with 22 additions and 12 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -104,7 +104,6 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"aquatic_cli_helpers",
|
"aquatic_cli_helpers",
|
||||||
"aquatic_http_protocol",
|
"aquatic_http_protocol",
|
||||||
"hashbrown",
|
|
||||||
"mimalloc",
|
"mimalloc",
|
||||||
"mio",
|
"mio",
|
||||||
"quickcheck",
|
"quickcheck",
|
||||||
|
|
@ -112,6 +111,7 @@ dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"rand_distr",
|
"rand_distr",
|
||||||
"serde",
|
"serde",
|
||||||
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -1680,6 +1680,12 @@ dependencies = [
|
||||||
"termcolor",
|
"termcolor",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
|
|
||||||
1
TODO.md
1
TODO.md
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
## aquatic_http_load_test
|
## aquatic_http_load_test
|
||||||
|
|
||||||
* use slab for connections? HashMap not necessary
|
|
||||||
* request sending: too many allocations, likely due to request to byte
|
* request sending: too many allocations, likely due to request to byte
|
||||||
conversion. optimize!
|
conversion. optimize!
|
||||||
* think about when to open new connections
|
* think about when to open new connections
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ name = "aquatic_http_load_test"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
aquatic_cli_helpers = { path = "../aquatic_cli_helpers" }
|
aquatic_cli_helpers = { path = "../aquatic_cli_helpers" }
|
||||||
aquatic_http_protocol = { path = "../aquatic_http_protocol" }
|
aquatic_http_protocol = { path = "../aquatic_http_protocol" }
|
||||||
hashbrown = { version = "0.7", features = ["serde"] }
|
|
||||||
mimalloc = { version = "0.1", default-features = false }
|
mimalloc = { version = "0.1", default-features = false }
|
||||||
mio = { version = "0.7", features = ["udp", "os-poll", "os-util"] }
|
mio = { version = "0.7", features = ["udp", "os-poll", "os-util"] }
|
||||||
rand = { version = "0.7", features = ["small_rng"] }
|
rand = { version = "0.7", features = ["small_rng"] }
|
||||||
rand_distr = "0.2"
|
rand_distr = "0.2"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
slab = "0.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.9"
|
quickcheck = "0.9"
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ use std::sync::atomic::Ordering;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::io::{Read, Write, ErrorKind};
|
use std::io::{Read, Write, ErrorKind};
|
||||||
|
|
||||||
use hashbrown::HashMap;
|
|
||||||
use mio::{net::TcpStream, Events, Poll, Interest, Token};
|
use mio::{net::TcpStream, Events, Poll, Interest, Token};
|
||||||
use rand::{rngs::SmallRng, prelude::*};
|
use rand::{rngs::SmallRng, prelude::*};
|
||||||
|
use slab::Slab;
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
|
|
@ -28,6 +28,10 @@ impl Connection {
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut stream = TcpStream::connect(config.server_address)?;
|
let mut stream = TcpStream::connect(config.server_address)?;
|
||||||
|
|
||||||
|
let entry = connections.vacant_entry();
|
||||||
|
|
||||||
|
*token_counter = entry.key();
|
||||||
|
|
||||||
poll.registry()
|
poll.registry()
|
||||||
.register(&mut stream, Token(*token_counter), Interest::READABLE)
|
.register(&mut stream, Token(*token_counter), Interest::READABLE)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -39,9 +43,7 @@ impl Connection {
|
||||||
can_send_initial: true,
|
can_send_initial: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
connections.insert(*token_counter, connection);
|
entry.insert(connection);
|
||||||
|
|
||||||
*token_counter = token_counter.wrapping_add(1);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +145,10 @@ impl Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub type ConnectionMap = HashMap<usize, Connection>;
|
pub type ConnectionMap = Slab<Connection>;
|
||||||
|
|
||||||
|
|
||||||
|
const NUM_CONNECTIONS: usize = 128;
|
||||||
|
|
||||||
|
|
||||||
pub fn run_socket_thread(
|
pub fn run_socket_thread(
|
||||||
|
|
@ -153,7 +158,7 @@ pub fn run_socket_thread(
|
||||||
) {
|
) {
|
||||||
let timeout = Duration::from_micros(config.network.poll_timeout_microseconds);
|
let timeout = Duration::from_micros(config.network.poll_timeout_microseconds);
|
||||||
|
|
||||||
let mut connections: ConnectionMap = HashMap::new();
|
let mut connections: ConnectionMap = Slab::with_capacity(NUM_CONNECTIONS);
|
||||||
let mut poll = Poll::new().expect("create poll");
|
let mut poll = Poll::new().expect("create poll");
|
||||||
let mut events = Events::with_capacity(config.network.poll_event_capacity);
|
let mut events = Events::with_capacity(config.network.poll_event_capacity);
|
||||||
let mut rng = SmallRng::from_entropy();
|
let mut rng = SmallRng::from_entropy();
|
||||||
|
|
@ -182,7 +187,7 @@ pub fn run_socket_thread(
|
||||||
if event.is_readable(){
|
if event.is_readable(){
|
||||||
let token = event.token();
|
let token = event.token();
|
||||||
|
|
||||||
if let Some(connection) = connections.get_mut(&token.0){
|
if let Some(connection) = connections.get_mut(token.0){
|
||||||
connection.read_response_and_send_request(
|
connection.read_response_and_send_request(
|
||||||
config,
|
config,
|
||||||
&state,
|
&state,
|
||||||
|
|
@ -195,7 +200,7 @@ pub fn run_socket_thread(
|
||||||
}
|
}
|
||||||
|
|
||||||
if !initial_sent {
|
if !initial_sent {
|
||||||
for connection in connections.values_mut(){
|
for (_, connection) in connections.iter_mut(){
|
||||||
if connection.can_send_initial {
|
if connection.can_send_initial {
|
||||||
connection.send_request(config, &state, &mut rng);
|
connection.send_request(config, &state, &mut rng);
|
||||||
|
|
||||||
|
|
@ -205,7 +210,7 @@ pub fn run_socket_thread(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slowly create new connections
|
// Slowly create new connections
|
||||||
if token_counter < 128 && iter_counter % CREATE_CONN_INTERVAL == 0 {
|
if token_counter < NUM_CONNECTIONS && iter_counter % CREATE_CONN_INTERVAL == 0 {
|
||||||
Connection::create_and_register(
|
Connection::create_and_register(
|
||||||
config,
|
config,
|
||||||
&mut connections,
|
&mut connections,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue