From c0e49bbab54d37d875a247f73bb22deb7c05c820 Mon Sep 17 00:00:00 2001 From: Revertron Date: Sat, 24 Apr 2021 19:02:24 +0200 Subject: [PATCH] Optimized p2p connections a bit. --- Cargo.toml | 2 +- alfis.toml | 2 +- src/commons/constants.rs | 2 +- src/p2p/network.rs | 5 ++++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a541c7..3a291cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "alfis" -version = "0.4.26" +version = "0.4.27" authors = ["Revertron "] edition = "2018" build = "build.rs" diff --git a/alfis.toml b/alfis.toml index c9460b9..0c8d1e0 100644 --- a/alfis.toml +++ b/alfis.toml @@ -33,4 +33,4 @@ forwarders = ["94.140.14.14:53", "94.140.15.15:53"] # How many CPU threads to spawn for mining, zero = number of CPU cores threads = 0 # Set lower priority for mining threads -lower = true +lower = true \ No newline at end of file diff --git a/src/commons/constants.rs b/src/commons/constants.rs index ab7ca42..273b1dc 100644 --- a/src/commons/constants.rs +++ b/src/commons/constants.rs @@ -43,5 +43,5 @@ pub const LOG_REFRESH_DELAY_SEC: u64 = 60; pub const POLL_TIMEOUT: Option = Some(Duration::from_millis(250)); pub const MAX_PACKET_SIZE: usize = 1 * 1024 * 1024; // 1 Mb -pub const MAX_READ_BLOCK_TIME: u128 = 500; +pub const MAX_READ_BLOCK_TIME: u128 = 200; pub const MAX_NODES: usize = 15; diff --git a/src/p2p/network.rs b/src/p2p/network.rs index bef17c0..de98736 100644 --- a/src/p2p/network.rs +++ b/src/p2p/network.rs @@ -353,8 +353,11 @@ fn read_message(stream: &mut TcpStream) -> Result, ()> { } // Would block "errors" are the OS's way of saying that the connection is not actually ready to perform this I/O operation. Err(ref err) if would_block(err) => { - // We give every connection no more than 500ms to read a message + // We give every connection no more than 200ms to read a message if instant.elapsed().as_millis() < MAX_READ_BLOCK_TIME { + // We need to sleep a bit, otherwise it can eat CPU + let delay = Duration::from_millis(10); + thread::sleep(delay); continue; } else { break;