mirror of
https://github.com/greatest-ape/aquatic.git
synced 2026-08-28 22:59:01 +00:00
udp: add statistics latencies flag, only calculate when set
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
latency histogram
|
||||
* use SyncHistogram?
|
||||
* avoid reporting zero (send more often?)
|
||||
* add config flag, don't calculate when turned off
|
||||
* cleaning
|
||||
|
||||
## Medium priority
|
||||
|
||||
@@ -17,6 +17,12 @@ pub const MAX_PACKET_SIZE: usize = 8192;
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct RequestTag(pub usize);
|
||||
|
||||
impl RequestTag {
|
||||
pub fn placeholder() -> Self {
|
||||
Self(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PendingScrapeRequest {
|
||||
pub slab_key: usize,
|
||||
|
||||
@@ -141,6 +141,8 @@ pub struct StatisticsConfig {
|
||||
pub write_html_to_file: bool,
|
||||
/// Path to save HTML file to
|
||||
pub html_file_path: PathBuf,
|
||||
/// Report response latencies
|
||||
pub latencies: bool,
|
||||
}
|
||||
|
||||
impl StatisticsConfig {
|
||||
@@ -156,6 +158,7 @@ impl Default for StatisticsConfig {
|
||||
print_to_stdout: false,
|
||||
write_html_to_file: false,
|
||||
html_file_path: "tmp/statistics.html".into(),
|
||||
latencies: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,9 @@ pub fn run_socket_worker(
|
||||
|
||||
last_pending_scrape_cleaning = now;
|
||||
}
|
||||
if now > last_histogram_sending + statistics_update_interval {
|
||||
if config.statistics.latencies
|
||||
& (now > last_histogram_sending + statistics_update_interval)
|
||||
{
|
||||
if let Err(err) = histogram_sender.try_send(latency_recorder.extract_histogram()) {
|
||||
::log::error!("Couldn't send latency data to statistics worker: {:#}", err);
|
||||
}
|
||||
@@ -345,7 +347,11 @@ fn read_requests(
|
||||
loop {
|
||||
match socket.recv_from(&mut buffer[..]) {
|
||||
Ok((amt, src)) => {
|
||||
let request_tag = latency_recorder.request_received();
|
||||
let request_tag = if config.statistics.latencies {
|
||||
latency_recorder.request_received()
|
||||
} else {
|
||||
RequestTag::placeholder()
|
||||
};
|
||||
|
||||
let res_request =
|
||||
Request::from_bytes(&buffer[..amt], config.protocol.max_scrape_torrents);
|
||||
@@ -580,7 +586,9 @@ fn send_response(
|
||||
|
||||
match socket.send_to(&cursor.get_ref()[..amt], addr) {
|
||||
Ok(amt) if config.statistics.active() => {
|
||||
latency_recorder.response_sent(tag);
|
||||
if config.statistics.latencies {
|
||||
latency_recorder.response_sent(tag);
|
||||
}
|
||||
|
||||
let stats = if canonical_addr_is_ipv4 {
|
||||
&state.statistics_ipv4
|
||||
|
||||
@@ -171,7 +171,8 @@ struct TemplateData {
|
||||
ipv6_active: bool,
|
||||
ipv4: FormattedStatistics,
|
||||
ipv6: FormattedStatistics,
|
||||
latency: LatencyData,
|
||||
latencies_active: bool,
|
||||
latencies: LatencyData,
|
||||
last_updated: String,
|
||||
peer_update_interval: String,
|
||||
}
|
||||
@@ -201,7 +202,7 @@ pub fn run_statistics_worker(
|
||||
loop {
|
||||
::std::thread::sleep(Duration::from_secs(config.statistics.interval));
|
||||
|
||||
let latency_data: LatencyData = histogram_receivers
|
||||
let latency_data = histogram_receivers
|
||||
.iter()
|
||||
.filter_map(|receiver| receiver.try_recv().ok())
|
||||
.sum::<Histogram<u64>>()
|
||||
@@ -215,7 +216,10 @@ pub fn run_statistics_worker(
|
||||
if config.statistics.print_to_stdout {
|
||||
println!("General:");
|
||||
println!(" access list entries: {}", state.access_list.load().len());
|
||||
println!(" {}", latency_data);
|
||||
|
||||
if config.statistics.latencies {
|
||||
println!(" {}", latency_data);
|
||||
}
|
||||
|
||||
if config.network.ipv4_active() {
|
||||
println!("IPv4:");
|
||||
@@ -236,7 +240,8 @@ pub fn run_statistics_worker(
|
||||
ipv6_active: config.network.ipv6_active(),
|
||||
ipv4: statistics_ipv4,
|
||||
ipv6: statistics_ipv6,
|
||||
latency: latency_data,
|
||||
latencies_active: config.statistics.latencies,
|
||||
latencies: latency_data,
|
||||
last_updated: OffsetDateTime::now_utc()
|
||||
.format(&Rfc2822)
|
||||
.unwrap_or("(formatting error)".into()),
|
||||
|
||||
@@ -20,31 +20,35 @@
|
||||
<strong>Updated:</strong> { last_updated } (UTC)
|
||||
</p>
|
||||
|
||||
{{ if latencies_active }}
|
||||
|
||||
<h2>Response latencies</h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th scope="row">Mean</th>
|
||||
<td>{ latency.mean } ms</td>
|
||||
<td>{ latencies.mean } ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Standard deviation</th>
|
||||
<td>{ latency.stdev } ms</td>
|
||||
<td>{ latencies.stdev } ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">95:th percentile</th>
|
||||
<td>{ latency.p95 } ms</td>
|
||||
<td>{ latencies.p95 } ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">99:th percentile</th>
|
||||
<td>{ latency.p99 } ms</td>
|
||||
<td>{ latencies.p99 } ms</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">99.9:th percentile</th>
|
||||
<td>{ latency.p999 } ms</td>
|
||||
<td>{ latencies.p999 } ms</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
{{ endif }}
|
||||
|
||||
{{ if ipv4_active }}
|
||||
|
||||
<h2>IPv4</h2>
|
||||
|
||||
Reference in New Issue
Block a user