Skip to content

Commit

Permalink
Add cache metrics to Stats and p9999 latency tracking to `Benchmark…
Browse files Browse the repository at this point in the history
…Report` (#1475)

This commit introduces cache metrics tracking and p9999 latency
measurement to improve performance monitoring and analysis. The
`human-repr` crate is added to enhance readability of large numbers in
logs and reports.

- Updated `Cargo.toml` and `Cargo.lock` to include `human-repr` dependency.
- Added cache metrics collection and serialization in both client and server.
- Implemented p9999 latency tracking in benchmark reports and analytics.
- Enhanced logging with human-readable counts and sizes using `human-repr`.
- Refactored code to accommodate new metrics and improve clarity.
  • Loading branch information
hubcio authored Feb 1, 2025
1 parent b0cd74b commit f859e17
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 53 deletions.
41 changes: 25 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bench"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "Apache-2.0"

Expand All @@ -13,6 +13,7 @@ clap = { version = "4.5.26", features = ["derive"] }
figlet-rs = "0.1.5"
futures = "0.3.31"
hostname = "0.4.0"
human-repr = "1.1.0"
iggy = { path = "../sdk" }
iggy-benchmark-report = { path = "report" }
integration = { path = "../integration" }
Expand Down
3 changes: 2 additions & 1 deletion bench/report/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iggy-benchmark-report"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
description = "Benchmark report and chart generation library for iggy-bench binary and iggy-benchmarks-dashboard web app"
license = "Apache-2.0"
Expand All @@ -11,6 +11,7 @@ charming = "0.4.0"
colored = "3.0.0"
derive-new = "0.7.0"
derive_more = { version = "1.0.0", features = ["full"] }
human-repr = "1.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sysinfo = "0.33.1"
Expand Down
14 changes: 9 additions & 5 deletions bench/report/src/plotting/text/subtext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
group_metrics_kind::GroupMetricsKind, params::BenchmarkParams, report::BenchmarkReport,
};
use byte_unit::{Byte, UnitType};
use human_repr::HumanCount;

impl BenchmarkReport {
pub fn subtext(&self) -> String {
Expand Down Expand Up @@ -74,13 +75,14 @@ impl BenchmarkGroupMetrics {

fn format_latency(&self) -> String {
format!(
"{} Latency • Avg: {:.2} ms • Med: {:.2} ms • P95: {:.2} ms • P99: {:.2} ms • P999: {:.2} ms",
"{} Latency • Avg: {:.2} ms • Med: {:.2} ms • P95: {:.2} ms • P99: {:.2} ms • P999: {:.2} ms • P9999: {:.2} ms",
self.summary.kind,
self.summary.average_latency_ms,
self.summary.average_median_latency_ms,
self.summary.average_p95_latency_ms,
self.summary.average_p99_latency_ms,
self.summary.average_p999_latency_ms
self.summary.average_p999_latency_ms,
self.summary.average_p9999_latency_ms
)
}
}
Expand All @@ -92,9 +94,8 @@ impl BenchmarkParams {
let messages_per_batch = self.messages_per_batch as u64;
let message_size = self.message_size as u64;

let sent: u64 = message_batches * messages_per_batch * message_size * self.producers as u64;
let polled: u64 =
message_batches * messages_per_batch * message_size * self.consumers as u64;
let sent = message_batches * messages_per_batch * message_size * self.producers as u64;
let polled = message_batches * messages_per_batch * message_size * self.consumers as u64;

let mut user_data_print = String::new();

Expand All @@ -116,6 +117,9 @@ impl BenchmarkParams {
));
}

let message_batches = message_batches.human_count_bare();
let messages_per_batch = messages_per_batch.human_count_bare();

let partitions = format!("{} partitions", self.partitions);

format!(
Expand Down
36 changes: 26 additions & 10 deletions bench/report/src/prints.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use colored::{Color, ColoredString, Colorize};
use human_repr::HumanCount;
use tracing::info;

use crate::{
Expand All @@ -18,18 +19,20 @@ impl BenchmarkReport {
let message_size = self.params.message_size;
let producers = self.params.producers;
let consumers = self.params.consumers;
let partitions = self.params.partitions;
println!();
let params_print = format!("Benchmark: {}, total messages: {}, total size: {} bytes, {} streams, {} messages per batch, {} batches, {} bytes per message, {} producers, {} consumers\n",
let params_print = format!("Benchmark: {}, {} producers, {} consumers, {} streams, {} partitions, {} total messages, {} messages per batch, {} batches, {} per message, {} total size\n",
kind,
total_messages,
total_size_bytes,
streams,
messages_per_batch,
message_batches,
message_size,
producers,
consumers,
).blue();
streams,
partitions,
total_messages.human_count_bare(),
messages_per_batch.human_count_bare(),
message_batches.human_count_bare(),
message_size.human_count_bytes(),
total_size_bytes.human_count_bytes(),
).blue();

info!("{}", params_print);

Expand Down Expand Up @@ -61,15 +64,28 @@ impl BenchmarkGroupMetrics {
let p95 = format!("{:.2}", self.summary.average_p95_latency_ms);
let p99 = format!("{:.2}", self.summary.average_p99_latency_ms);
let p999 = format!("{:.2}", self.summary.average_p999_latency_ms);
let p9999 = format!("{:.2}", self.summary.average_p9999_latency_ms);
let avg = format!("{:.2}", self.summary.average_latency_ms);
let median = format!("{:.2}", self.summary.average_median_latency_ms);

format!(
"{}: Total throughput: {} MB/s, {} messages/s, average throughput per {}: {} MB/s, \
p50 latency: {} ms, p90 latency: {} ms, p95 latency: {} ms, \
p99 latency: {} ms, p999 latency: {} ms, average latency: {} ms, \
p99 latency: {} ms, p999 latency: {} ms, p9999 latency: {} ms, average latency: {} ms, \
median latency: {} ms",
prefix, total_mb, total_msg, actor, avg_mb, p50, p90, p95, p99, p999, avg, median,
prefix,
total_mb,
total_msg,
actor,
avg_mb,
p50,
p90,
p95,
p99,
p999,
p9999,
avg,
median,
)
.color(color)
}
Expand Down
2 changes: 2 additions & 0 deletions bench/report/src/types/group_metrics_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct BenchmarkGroupMetricsSummary {
#[serde(serialize_with = "round_float")]
pub average_p999_latency_ms: f64,
#[serde(serialize_with = "round_float")]
pub average_p9999_latency_ms: f64,
#[serde(serialize_with = "round_float")]
pub average_latency_ms: f64,
#[serde(serialize_with = "round_float")]
pub average_median_latency_ms: f64,
Expand Down
2 changes: 2 additions & 0 deletions bench/report/src/types/individual_metrics_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct BenchmarkIndividualMetricsSummary {
#[serde(serialize_with = "round_float")]
pub p999_latency_ms: f64,
#[serde(serialize_with = "round_float")]
pub p9999_latency_ms: f64,
#[serde(serialize_with = "round_float")]
pub avg_latency_ms: f64,
#[serde(serialize_with = "round_float")]
pub median_latency_ms: f64,
Expand Down
21 changes: 15 additions & 6 deletions bench/src/actors/consumer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::analytics::metrics::individual::from_records;
use crate::analytics::record::BenchmarkRecord;
use crate::rate_limiter::RateLimiter;
use human_repr::HumanCount;
use iggy::client::{ConsumerGroupClient, MessageClient};
use iggy::clients::client::IggyClient;
use iggy::consumer::Consumer as IggyConsumer;
Expand Down Expand Up @@ -149,12 +150,19 @@ impl Consumer {
if let Some(cg_id) = self.consumer_group_id {
info!(
"Consumer #{}, part of consumer group #{} → polling {} messages in {} batches of {} messages...",
self.consumer_id, cg_id, total_messages, message_batches, messages_per_batch
self.consumer_id,
cg_id,
total_messages.human_count_bare(),
message_batches.human_count_bare(),
messages_per_batch.human_count_bare()
);
} else {
info!(
"Consumer #{} → polling {} messages in {} batches of {} messages...",
self.consumer_id, total_messages, message_batches, messages_per_batch
self.consumer_id,
total_messages.human_count_bare(),
message_batches.human_count_bare(),
messages_per_batch.human_count_bare()
);
}

Expand Down Expand Up @@ -282,11 +290,11 @@ impl Consumer {
info!(
"Consumer #{} → polled {} messages, {} batches of {} messages in {:.2} s, total size: {}, average throughput: {:.2} MB/s, \
p50 latency: {:.2} ms, p90 latency: {:.2} ms, p95 latency: {:.2} ms, p99 latency: {:.2} ms, p999 latency: {:.2} ms, \
average latency: {:.2} ms, median latency: {:.2} ms",
p9999 latency: {:.2} ms, average latency: {:.2} ms, median latency: {:.2} ms",
consumer_id,
total_messages,
message_batches,
messages_per_batch,
total_messages.human_count_bare(),
message_batches.human_count_bare(),
messages_per_batch.human_count_bare(),
stats.summary.total_time_secs,
IggyByteSize::from(stats.summary.total_user_data_bytes),
stats.summary.throughput_megabytes_per_second,
Expand All @@ -295,6 +303,7 @@ impl Consumer {
stats.summary.p95_latency_ms,
stats.summary.p99_latency_ms,
stats.summary.p999_latency_ms,
stats.summary.p9999_latency_ms,
stats.summary.avg_latency_ms,
stats.summary.median_latency_ms
);
Expand Down
9 changes: 7 additions & 2 deletions bench/src/actors/producer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::analytics::metrics::individual::from_records;
use crate::analytics::record::BenchmarkRecord;
use crate::rate_limiter::RateLimiter;
use human_repr::HumanCount;
use iggy::client::MessageClient;
use iggy::clients::client::IggyClient;
use iggy::error::IggyError;
Expand Down Expand Up @@ -114,7 +115,10 @@ impl Producer {

info!(
"Producer #{} → sending {} messages in {} batches of {} messages...",
self.producer_id, total_messages, message_batches, messages_per_batch
self.producer_id,
total_messages.human_count_bare(),
message_batches.human_count_bare(),
messages_per_batch.human_count_bare()
);

let start_timestamp = Instant::now();
Expand Down Expand Up @@ -185,7 +189,7 @@ impl Producer {
) {
info!(
"Producer #{} → sent {} messages in {} batches of {} messages in {:.2} s, total size: {}, average throughput: {:.2} MB/s, \
p50 latency: {:.2} ms, p90 latency: {:.2} ms, p95 latency: {:.2} ms, p99 latency: {:.2} ms, p999 latency: {:.2} ms, \
p50 latency: {:.2} ms, p90 latency: {:.2} ms, p95 latency: {:.2} ms, p99 latency: {:.2} ms, p999 latency: {:.2} ms, p9999 latency: {:.2} ms, \
average latency: {:.2} ms, median latency: {:.2} ms",
producer_id,
total_messages,
Expand All @@ -199,6 +203,7 @@ impl Producer {
stats.summary.p95_latency_ms,
stats.summary.p99_latency_ms,
stats.summary.p999_latency_ms,
stats.summary.p9999_latency_ms,
stats.summary.avg_latency_ms,
stats.summary.median_latency_ms
);
Expand Down
Loading

0 comments on commit f859e17

Please sign in to comment.