mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
Merge pull request #15 from greatest-ape/udp-fixes
aquatic_udp mio implementation: clean connections according to interval, print more statistics
This commit is contained in:
commit
5a1bedfe85
2 changed files with 34 additions and 9 deletions
|
|
@ -4,7 +4,7 @@ use std::sync::{
|
|||
atomic::{AtomicUsize, Ordering},
|
||||
Arc,
|
||||
};
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::vec::Drain;
|
||||
|
||||
use aquatic_common::access_list::AccessListQuery;
|
||||
|
|
@ -53,6 +53,7 @@ pub fn run_socket_worker(
|
|||
let timeout = Duration::from_millis(50);
|
||||
|
||||
let mut iter_counter = 0usize;
|
||||
let mut last_cleaning = Instant::now();
|
||||
|
||||
loop {
|
||||
poll.poll(&mut events, Some(timeout))
|
||||
|
|
@ -84,13 +85,17 @@ pub fn run_socket_worker(
|
|||
local_responses.drain(..),
|
||||
);
|
||||
|
||||
iter_counter += 1;
|
||||
if iter_counter % 32 == 0 {
|
||||
let now = Instant::now();
|
||||
|
||||
if iter_counter == 1000 {
|
||||
connections.clean();
|
||||
if last_cleaning + Duration::from_secs(config.cleaning.interval) > now {
|
||||
connections.clean();
|
||||
|
||||
iter_counter = 0;
|
||||
last_cleaning = now;
|
||||
}
|
||||
}
|
||||
|
||||
iter_counter = iter_counter.wrapping_add(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,27 +38,47 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
|
|||
bytes_sent_per_second * 8.0 / 1_000_000.0,
|
||||
);
|
||||
|
||||
let mut total_num_torrents_ipv4 = 0usize;
|
||||
let mut total_num_torrents_ipv6 = 0usize;
|
||||
let mut total_num_peers_ipv4 = 0usize;
|
||||
let mut total_num_peers_ipv6 = 0usize;
|
||||
|
||||
let mut peers_per_torrent = Histogram::new();
|
||||
|
||||
{
|
||||
let torrents = &mut state.torrents.lock();
|
||||
|
||||
for torrent in torrents.ipv4.values() {
|
||||
let num_peers = (torrent.num_seeders + torrent.num_leechers) as u64;
|
||||
let num_peers = torrent.num_seeders + torrent.num_leechers;
|
||||
|
||||
if let Err(err) = peers_per_torrent.increment(num_peers) {
|
||||
if let Err(err) = peers_per_torrent.increment(num_peers as u64) {
|
||||
::log::error!("error incrementing peers_per_torrent histogram: {}", err)
|
||||
}
|
||||
|
||||
total_num_peers_ipv4 += num_peers;
|
||||
}
|
||||
for torrent in torrents.ipv6.values() {
|
||||
let num_peers = (torrent.num_seeders + torrent.num_leechers) as u64;
|
||||
let num_peers = torrent.num_seeders + torrent.num_leechers;
|
||||
|
||||
if let Err(err) = peers_per_torrent.increment(num_peers) {
|
||||
if let Err(err) = peers_per_torrent.increment(num_peers as u64) {
|
||||
::log::error!("error incrementing peers_per_torrent histogram: {}", err)
|
||||
}
|
||||
|
||||
total_num_peers_ipv6 += num_peers;
|
||||
}
|
||||
|
||||
total_num_torrents_ipv4 += torrents.ipv4.len();
|
||||
total_num_torrents_ipv6 += torrents.ipv6.len();
|
||||
}
|
||||
|
||||
println!(
|
||||
"ipv4 torrents: {}, peers: {}; ipv6 torrents: {}, peers: {}",
|
||||
total_num_torrents_ipv4,
|
||||
total_num_peers_ipv4,
|
||||
total_num_torrents_ipv6,
|
||||
total_num_peers_ipv6,
|
||||
);
|
||||
|
||||
if peers_per_torrent.entries() != 0 {
|
||||
println!(
|
||||
"peers per torrent: min: {}, p50: {}, p75: {}, p90: {}, p99: {}, p999: {}, max: {}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue