aquatic: Config: add fields for max handler request, channel timeout

This commit is contained in:
Joakim Frostegård 2020-04-12 13:26:44 +02:00
parent e61c961126
commit 5430e561f5
3 changed files with 24 additions and 5 deletions

View file

@ -1,12 +1,10 @@
# TODO # TODO
## aquatic ## aquatic
* thread 'main' panicked at 'overflow when subtracting duration from instant', src/libstd/time.rs:374:9 * `thread 'main' panicked at 'overflow when subtracting duration from instant', src/libstd/time.rs:374:9`
* Put connections and torrent in a struct behind a commong lock. Add * Put connections and torrent in a struct behind a commong lock. Add
functionality for checking if mutex is unlocked before quitting to functionality for checking if mutex is unlocked before quitting to
collect requests from channel (try_recv) up to a limit. collect requests from channel (try_recv) up to a limit.
* Add config variable like "handler_max_requests" (default 1024?)
* Shorter timeout on handler channel collector (1ms?)
* Handle Ipv4 and Ipv6 peers. Probably split state. Ipv4 peers can't make * Handle Ipv4 and Ipv6 peers. Probably split state. Ipv4 peers can't make
use of Ipv6 ones. Ipv6 ones may or may note be able to make use of Ipv4 use of Ipv6 ones. Ipv6 ones may or may note be able to make use of Ipv4
ones, have to check. ones, have to check.

View file

@ -9,6 +9,7 @@ pub struct Config {
pub socket_workers: usize, pub socket_workers: usize,
pub response_workers: usize, pub response_workers: usize,
pub network: NetworkConfig, pub network: NetworkConfig,
pub handlers: HandlerConfig,
pub statistics: StatisticsConfig, pub statistics: StatisticsConfig,
pub cleaning: CleaningConfig, pub cleaning: CleaningConfig,
} }
@ -30,6 +31,13 @@ pub struct NetworkConfig {
} }
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HandlerConfig {
pub max_requests_per_iter: usize,
pub channel_recv_timeout_ms: u64,
}
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StatisticsConfig { pub struct StatisticsConfig {
/// Print statistics this often (seconds). Don't print when set to zero. /// Print statistics this often (seconds). Don't print when set to zero.
@ -54,6 +62,7 @@ impl Default for Config {
socket_workers: 1, socket_workers: 1,
response_workers: 1, response_workers: 1,
network: NetworkConfig::default(), network: NetworkConfig::default(),
handlers: HandlerConfig::default(),
statistics: StatisticsConfig::default(), statistics: StatisticsConfig::default(),
cleaning: CleaningConfig::default(), cleaning: CleaningConfig::default(),
} }
@ -75,6 +84,16 @@ impl Default for NetworkConfig {
} }
impl Default for HandlerConfig {
fn default() -> Self {
Self {
max_requests_per_iter: 2048,
channel_recv_timeout_ms: 1,
}
}
}
impl Default for StatisticsConfig { impl Default for StatisticsConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {

View file

@ -26,10 +26,12 @@ pub fn handle(
let mut std_rng = StdRng::from_entropy(); let mut std_rng = StdRng::from_entropy();
let mut small_rng = SmallRng::from_rng(&mut std_rng).unwrap(); let mut small_rng = SmallRng::from_rng(&mut std_rng).unwrap();
let timeout = Duration::from_millis(10); let timeout = Duration::from_millis(
config.handlers.channel_recv_timeout_ms
);
loop { loop {
for i in 0..1000 { for i in 0..config.handlers.max_requests_per_iter {
let (request, src): (Request, SocketAddr) = if i == 0 { let (request, src): (Request, SocketAddr) = if i == 0 {
match request_receiver.recv(){ match request_receiver.recv(){
Ok(r) => r, Ok(r) => r,