mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
Run cargo fmt, clean up imports
This commit is contained in:
parent
80447d9d1b
commit
49ed4371e7
13 changed files with 125 additions and 83 deletions
|
|
@ -61,9 +61,11 @@ fn run(config: Config) -> ::anyhow::Result<()> {
|
|||
let tls_config = tls_config.clone();
|
||||
let state = state.clone();
|
||||
|
||||
LocalExecutorBuilder::default().spawn(|| async move {
|
||||
run_socket_thread(config, tls_config, state).await.unwrap();
|
||||
}).unwrap();
|
||||
LocalExecutorBuilder::default()
|
||||
.spawn(|| async move {
|
||||
run_socket_thread(config, tls_config, state).await.unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
monitor_statistics(state, &config);
|
||||
|
|
@ -175,8 +177,10 @@ fn create_tls_config() -> anyhow::Result<Arc<rustls::ClientConfig>> {
|
|||
.with_safe_defaults()
|
||||
.with_root_certificates(rustls::RootCertStore::empty())
|
||||
.with_no_client_auth();
|
||||
|
||||
config.dangerous().set_certificate_verifier(Arc::new(FakeCertificateVerifier));
|
||||
|
||||
|
||||
config
|
||||
.dangerous()
|
||||
.set_certificate_verifier(Arc::new(FakeCertificateVerifier));
|
||||
|
||||
Ok(Arc::new(config))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
use std::{cell::RefCell, convert::TryInto, io::{Cursor, ErrorKind, Read}, rc::Rc, sync::{Arc, atomic::Ordering}, time::Duration};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
convert::TryInto,
|
||||
io::{Cursor, ErrorKind, Read},
|
||||
rc::Rc,
|
||||
sync::{atomic::Ordering, Arc},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use aquatic_http_protocol::response::Response;
|
||||
use futures_lite::{AsyncReadExt, AsyncWriteExt};
|
||||
use glommio::{prelude::*, timer::TimerActionRepeat};
|
||||
use glommio::net::TcpStream;
|
||||
use rand::{SeedableRng, prelude::SmallRng};
|
||||
use glommio::{prelude::*, timer::TimerActionRepeat};
|
||||
use rand::{prelude::SmallRng, SeedableRng};
|
||||
use rustls::ClientConnection;
|
||||
|
||||
use crate::{common::LoadTestState, config::Config, utils::create_random_request};
|
||||
|
|
@ -17,12 +24,14 @@ pub async fn run_socket_thread(
|
|||
let config = Rc::new(config);
|
||||
let num_active_connections = Rc::new(RefCell::new(0usize));
|
||||
|
||||
TimerActionRepeat::repeat(move || periodically_open_connections(
|
||||
config.clone(),
|
||||
tls_config.clone(),
|
||||
load_test_state.clone(),
|
||||
num_active_connections.clone())
|
||||
);
|
||||
TimerActionRepeat::repeat(move || {
|
||||
periodically_open_connections(
|
||||
config.clone(),
|
||||
tls_config.clone(),
|
||||
load_test_state.clone(),
|
||||
num_active_connections.clone(),
|
||||
)
|
||||
});
|
||||
|
||||
futures_lite::future::pending::<bool>().await;
|
||||
|
||||
|
|
@ -37,10 +46,13 @@ async fn periodically_open_connections(
|
|||
) -> Option<Duration> {
|
||||
if *num_active_connections.borrow() < config.num_connections {
|
||||
spawn_local(async move {
|
||||
if let Err(err) = Connection::run(config, tls_config, load_test_state, num_active_connections).await {
|
||||
if let Err(err) =
|
||||
Connection::run(config, tls_config, load_test_state, num_active_connections).await
|
||||
{
|
||||
eprintln!("connection creation error: {:?}", err);
|
||||
}
|
||||
}).detach();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
Some(Duration::from_secs(1))
|
||||
|
|
@ -65,7 +77,8 @@ impl Connection {
|
|||
load_test_state: LoadTestState,
|
||||
num_active_connections: Rc<RefCell<usize>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let stream = TcpStream::connect(config.server_address).await
|
||||
let stream = TcpStream::connect(config.server_address)
|
||||
.await
|
||||
.map_err(|err| anyhow::anyhow!("connect: {:?}", err))?;
|
||||
let tls = ClientConnection::new(tls_config, "example.com".try_into().unwrap()).unwrap();
|
||||
let rng = SmallRng::from_entropy();
|
||||
|
|
@ -98,7 +111,8 @@ impl Connection {
|
|||
async fn run_connection_loop(&mut self) -> anyhow::Result<()> {
|
||||
loop {
|
||||
if self.send_new_request {
|
||||
let request = create_random_request(&self.config, &self.load_test_state, &mut self.rng);
|
||||
let request =
|
||||
create_random_request(&self.config, &self.load_test_state, &mut self.rng);
|
||||
|
||||
request.write(&mut self.tls.writer())?;
|
||||
self.queued_responses += 1;
|
||||
|
|
@ -121,8 +135,7 @@ impl Connection {
|
|||
return Err(anyhow::anyhow!("Peer has closed connection"));
|
||||
}
|
||||
|
||||
self
|
||||
.load_test_state
|
||||
self.load_test_state
|
||||
.statistics
|
||||
.bytes_received
|
||||
.fetch_add(bytes_read, Ordering::SeqCst);
|
||||
|
|
@ -145,7 +158,8 @@ impl Connection {
|
|||
if end > self.response_buffer.len() {
|
||||
return Err(anyhow::anyhow!("response too large"));
|
||||
} else {
|
||||
let response_buffer_slice = &mut self.response_buffer[self.response_buffer_position..end];
|
||||
let response_buffer_slice =
|
||||
&mut self.response_buffer[self.response_buffer_position..end];
|
||||
|
||||
response_buffer_slice.copy_from_slice(&buf[..amt]);
|
||||
|
||||
|
|
@ -182,25 +196,21 @@ impl Connection {
|
|||
|
||||
match Response::from_bytes(interesting_bytes) {
|
||||
Ok(response) => {
|
||||
|
||||
match response {
|
||||
Response::Announce(_) => {
|
||||
self
|
||||
.load_test_state
|
||||
self.load_test_state
|
||||
.statistics
|
||||
.responses_announce
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
Response::Scrape(_) => {
|
||||
self
|
||||
.load_test_state
|
||||
self.load_test_state
|
||||
.statistics
|
||||
.responses_scrape
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
Response::Failure(response) => {
|
||||
self
|
||||
.load_test_state
|
||||
self.load_test_state
|
||||
.statistics
|
||||
.responses_failure
|
||||
.fetch_add(1, Ordering::SeqCst);
|
||||
|
|
@ -253,18 +263,20 @@ impl Connection {
|
|||
self.stream.write_all(&buf.into_inner()).await?;
|
||||
self.stream.flush().await?;
|
||||
|
||||
self
|
||||
.load_test_state
|
||||
self.load_test_state
|
||||
.statistics
|
||||
.bytes_sent
|
||||
.fetch_add(len, Ordering::SeqCst);
|
||||
|
||||
if self.queued_responses != 0 {
|
||||
self.load_test_state.statistics.requests.fetch_add(self.queued_responses, Ordering::SeqCst);
|
||||
self.load_test_state
|
||||
.statistics
|
||||
.requests
|
||||
.fetch_add(self.queued_responses, Ordering::SeqCst);
|
||||
|
||||
self.queued_responses = 0;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue