mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 18:55:32 +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},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::{Duration, Instant};
|
||||||
use std::vec::Drain;
|
use std::vec::Drain;
|
||||||
|
|
||||||
use aquatic_common::access_list::AccessListQuery;
|
use aquatic_common::access_list::AccessListQuery;
|
||||||
|
|
@ -53,6 +53,7 @@ pub fn run_socket_worker(
|
||||||
let timeout = Duration::from_millis(50);
|
let timeout = Duration::from_millis(50);
|
||||||
|
|
||||||
let mut iter_counter = 0usize;
|
let mut iter_counter = 0usize;
|
||||||
|
let mut last_cleaning = Instant::now();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
poll.poll(&mut events, Some(timeout))
|
poll.poll(&mut events, Some(timeout))
|
||||||
|
|
@ -84,14 +85,18 @@ pub fn run_socket_worker(
|
||||||
local_responses.drain(..),
|
local_responses.drain(..),
|
||||||
);
|
);
|
||||||
|
|
||||||
iter_counter += 1;
|
if iter_counter % 32 == 0 {
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
if iter_counter == 1000 {
|
if last_cleaning + Duration::from_secs(config.cleaning.interval) > now {
|
||||||
connections.clean();
|
connections.clean();
|
||||||
|
|
||||||
iter_counter = 0;
|
last_cleaning = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iter_counter = iter_counter.wrapping_add(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_socket(config: &Config) -> ::std::net::UdpSocket {
|
fn create_socket(config: &Config) -> ::std::net::UdpSocket {
|
||||||
|
|
|
||||||
|
|
@ -38,27 +38,47 @@ pub fn gather_and_print_statistics(state: &State, config: &Config) {
|
||||||
bytes_sent_per_second * 8.0 / 1_000_000.0,
|
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 mut peers_per_torrent = Histogram::new();
|
||||||
|
|
||||||
{
|
{
|
||||||
let torrents = &mut state.torrents.lock();
|
let torrents = &mut state.torrents.lock();
|
||||||
|
|
||||||
for torrent in torrents.ipv4.values() {
|
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)
|
::log::error!("error incrementing peers_per_torrent histogram: {}", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
total_num_peers_ipv4 += num_peers;
|
||||||
}
|
}
|
||||||
for torrent in torrents.ipv6.values() {
|
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)
|
::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 {
|
if peers_per_torrent.entries() != 0 {
|
||||||
println!(
|
println!(
|
||||||
"peers per torrent: min: {}, p50: {}, p75: {}, p90: {}, p99: {}, p999: {}, max: {}",
|
"peers per torrent: min: {}, p50: {}, p75: {}, p90: {}, p99: {}, p999: {}, max: {}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue