forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
streamer send destination metrics for repair, gossip (solana-labs#21564)
- Loading branch information
Showing
11 changed files
with
215 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::{ | ||
result::Result, | ||
sync::{ | ||
atomic::{AtomicBool, Ordering}, | ||
mpsc::{Receiver, RecvTimeoutError}, | ||
Arc, | ||
}, | ||
thread::{self, Builder, JoinHandle}, | ||
time::Duration, | ||
}; | ||
|
||
pub struct StatsReporterService { | ||
thread_hdl: JoinHandle<()>, | ||
} | ||
|
||
impl StatsReporterService { | ||
pub fn new( | ||
reporting_receiver: Receiver<Box<dyn FnOnce() + Send>>, | ||
exit: &Arc<AtomicBool>, | ||
) -> Self { | ||
let exit = exit.clone(); | ||
let thread_hdl = Builder::new() | ||
.name("solana-stats-reporter".to_owned()) | ||
.spawn(move || loop { | ||
if exit.load(Ordering::Relaxed) { | ||
return; | ||
} | ||
if let Err(e) = Self::receive_reporting_func(&reporting_receiver) { | ||
match e { | ||
RecvTimeoutError::Disconnected => break, | ||
RecvTimeoutError::Timeout => (), | ||
} | ||
} | ||
}) | ||
.unwrap(); | ||
|
||
Self { thread_hdl } | ||
} | ||
|
||
pub fn join(self) -> thread::Result<()> { | ||
self.thread_hdl.join()?; | ||
Ok(()) | ||
} | ||
|
||
fn receive_reporting_func( | ||
r: &Receiver<Box<dyn FnOnce() + Send>>, | ||
) -> Result<(), RecvTimeoutError> { | ||
let timer = Duration::new(1, 0); | ||
let func = r.recv_timeout(timer)?; | ||
func(); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.