reworked idle throttling a bit
This commit is contained in:
parent
1a1e0591a1
commit
5cc6259c0a
29
sunbeam.rs
29
sunbeam.rs
|
@ -9,12 +9,18 @@ use std::sync::mpsc;
|
|||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
static IDLE_THRESH:usize = 65536;
|
||||
static BUFFERSIZE_INITIAL:usize = 511;
|
||||
static IDLE_THRESH:u64 = 256; // cycles of doing nothing before throttling back to slightly slower execution speed
|
||||
static IDLE_SCALING:u64 = 1; // after crossing IDLE_THRESH, increase cycle delay by this many microseconds per cycle
|
||||
static IDLE_MAX:u64 = 65535; // maximum number of idle cycles to count up before stopping to count
|
||||
// IDLE_MAX*IDLE_SCALING-IDLE_THRESH = maximum cycle delay in microseconds
|
||||
|
||||
static LOOPBACK_FLAG:&str = "-l";
|
||||
static BLOCKFILE_NAME:&str = ".nosunbeam";
|
||||
static ALLOWFILE_NAME:&str = ".yesunbeam";
|
||||
static RECONNECT_WAIT:u64 = 1000; // time in ms to wait between reconnect attempts
|
||||
|
||||
static BUFFERSIZE_INITIAL:usize = 511; // how big the buffer capacity should be to start: bigger = maybe faster but more memory usage
|
||||
|
||||
static LOOPBACK_FLAG:&str = "-l"; // flag passed to sunbeam to activate loopback mode
|
||||
static BLOCKFILE_NAME:&str = ".nosunbeam"; // file to check for as the client blacklist
|
||||
static ALLOWFILE_NAME:&str = ".yesunbeam"; // file to check for as the client whitelist, for Whitelist-mode connectors
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(Clone)]
|
||||
|
@ -144,7 +150,7 @@ fn main() {
|
|||
|
||||
let (maintx,mainrx) = mpsc::channel();
|
||||
|
||||
let mut idlecycles:usize = 0;
|
||||
let mut idlecycles:u64 = 0;
|
||||
let mut bottle:Vec<u8> = Vec::with_capacity(BUFFERSIZE_INITIAL);
|
||||
|
||||
let mut sources:VecDeque<(TcpStream,SocketAddr)> = VecDeque::new();
|
||||
|
@ -164,7 +170,7 @@ fn main() {
|
|||
}
|
||||
|
||||
loop {
|
||||
if idlecycles < IDLE_THRESH {
|
||||
if idlecycles < IDLE_MAX {
|
||||
idlecycles += 1;
|
||||
}
|
||||
|
||||
|
@ -261,10 +267,7 @@ fn main() {
|
|||
thread::spawn(move || {
|
||||
loop {
|
||||
match TcpStream::connect(&threadaddress) {
|
||||
Err(why) => {
|
||||
eprintln!("-!- failed to reconnect to remote resource ({}): {}. trying to reconnect...",threadaddress,why);
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
},
|
||||
Err(_why) => thread::sleep(Duration::from_millis(RECONNECT_WAIT)),
|
||||
Ok(stream) => {
|
||||
stream.set_nonblocking(true).expect("cannot set stream to nonblocking");
|
||||
stream.set_nodelay(true).expect("cannot set stream to nodelay");
|
||||
|
@ -280,8 +283,8 @@ fn main() {
|
|||
sources.push_back(reconnection);
|
||||
}
|
||||
|
||||
if idlecycles >= IDLE_THRESH {
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
if idlecycles > IDLE_THRESH {
|
||||
thread::sleep(Duration::from_micros(idlecycles*IDLE_SCALING-IDLE_THRESH));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue