Skip to content

Commit

Permalink
Refactor benchmark output handling and add JSON/HTML support
Browse files Browse the repository at this point in the history
This commit refactors the benchmark output handling by replacing CSV and TOML
file generation with JSON and HTML outputs. The `output_directory` argument is
replaced with `output`, and the results are now serialized into a JSON file.
Additionally, HTML plots are generated using the `charming` library, providing
a visual representation of throughput and latency over time.

- Removed CSV and TOML dependencies and related code.
- Added `charming` and `serde_json` dependencies for JSON and HTML output.
- Updated scripts to reflect changes in output handling.
- Improved directory handling in performance scripts.
  • Loading branch information
hubcio committed Jan 16, 2025
1 parent 7155d50 commit d537a0b
Show file tree
Hide file tree
Showing 22 changed files with 987 additions and 205 deletions.
102 changes: 80 additions & 22 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ license = "Apache-2.0"

[dependencies]
async-trait = "0.1.84"
charming = "0.4.0"
chrono = "0.4.31"
clap = { version = "4.5.23", features = ["derive"] }
colored = "2.2.0"
csv = "1.3.1"
derive-new = "0.7.0"
derive_more = "1.0.0"
figlet-rs = "0.1.5"
Expand All @@ -18,6 +19,8 @@ iggy = { path = "../sdk" }
integration = { path = "../integration" }
nonzero_lit = "0.1.2"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.114"
sysinfo = "0.33.1"
tokio = { version = "1.42.0", features = ["full"] }
toml = "0.8.19"
tracing = { version = "0.1.41" }
Expand Down
48 changes: 40 additions & 8 deletions bench/src/args/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ pub struct IggyBenchArgs {
#[arg(long, short = 'k', default_value_t = DEFAULT_SKIP_SERVER_START)]
pub skip_server_start: bool,

/// Output directory, in which the benchmark results will be stored as `csv` and `toml` files.
/// Sample from the benchmark will be stored in a `csv` file on per-actor manner - each
/// producer/consumer will have its own file.
/// Actor summary, benchmark summary and parameters will be stored in a TOML file.
#[arg(long, short = 'o', default_value = None)]
pub output_directory: Option<String>,
/// Output directory path for the benchmark results
#[arg(long, short)]
pub output: Option<String>,

/// Git reference (commit hash, branch or tag) used for note in the benchmark results
#[arg(long)]
pub git_ref: Option<String>,

/// Git reference date used for note in the benchmark results, preferably merge date of the commit
#[arg(long)]
pub git_ref_date: Option<String>,

/// Pretty name for the benchmark run
#[arg(long)]
pub pretty_name: Option<String>,
}

fn validate_server_executable_path(v: &str) -> Result<String, String> {
Expand Down Expand Up @@ -90,6 +99,17 @@ impl IggyBenchArgs {
.exit();
}

if self.output.is_none()
&& (self.git_ref.is_some() || self.pretty_name.is_some() || self.git_ref_date.is_some())
{
IggyBenchArgs::command()
.error(
ErrorKind::ArgumentConflict,
"--git-ref, --git-ref-date and --pretty-name can only be used when --output is specified",
)
.exit();
}

self.benchmark_kind.inner().validate()
}

Expand Down Expand Up @@ -141,7 +161,19 @@ impl IggyBenchArgs {
self.warmup_time
}

pub fn output_directory(&self) -> Option<String> {
self.output_directory.clone()
pub fn output(&self) -> Option<String> {
self.output.clone()
}

pub fn pretty_name(&self) -> Option<String> {
self.pretty_name.clone()
}

pub fn git_ref(&self) -> Option<String> {
self.git_ref.clone()
}

pub fn git_ref_date(&self) -> Option<String> {
self.git_ref_date.clone()
}
}
3 changes: 2 additions & 1 deletion bench/src/args/simple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use derive_more::Display;
use serde::Serialize;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Display, Serialize)]
pub enum BenchmarkKind {
#[display("send messages")]
Send,
Expand Down
56 changes: 27 additions & 29 deletions bench/src/benchmark_params.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,42 @@
use std::io::Write;

use crate::args::common::IggyBenchArgs;
use chrono::{DateTime, Utc};
use iggy::utils::timestamp::IggyTimestamp;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct BenchmarkParams {
timestamp_micros: i64,
benchmark_name: String,
transport: String,
messages_per_batch: u32,
message_batches: u32,
message_size: u32,
producers: u32,
consumers: u32,
streams: u32,
partitions: u32,
number_of_consumer_groups: u32,
disable_parallel_consumers: bool,
disable_parallel_producers: bool,
}

impl BenchmarkParams {
pub fn dump_to_toml(&self, output_directory: &str) {
let output_file = format!("{}/params.toml", output_directory);
let toml_str = toml::to_string(self).unwrap();
Write::write_all(
&mut std::fs::File::create(output_file).unwrap(),
toml_str.as_bytes(),
)
.unwrap();
}
pub timestamp: String,
pub benchmark_kind: String,
pub transport: String,
pub pretty_name: Option<String>,
pub git_ref: Option<String>,
pub git_ref_date: Option<String>,
pub messages_per_batch: u32,
pub message_batches: u32,
pub message_size: u32,
pub producers: u32,
pub consumers: u32,
pub streams: u32,
pub partitions: u32,
pub number_of_consumer_groups: u32,
pub disable_parallel_consumers: bool,
pub disable_parallel_producers: bool,
}

impl From<&IggyBenchArgs> for BenchmarkParams {
fn from(args: &IggyBenchArgs) -> Self {
let timestamp =
DateTime::<Utc>::from_timestamp_micros(IggyTimestamp::now().as_micros() as i64)
.map(|dt| dt.to_rfc3339())
.unwrap_or_else(|| String::from("unknown"));

BenchmarkParams {
timestamp_micros: IggyTimestamp::now().as_micros() as i64,
benchmark_name: args.benchmark_kind.as_simple_kind().to_string(),
timestamp,
benchmark_kind: args.benchmark_kind.as_simple_kind().to_string(),
transport: args.transport().to_string(),
pretty_name: args.pretty_name(),
git_ref: args.git_ref(),
git_ref_date: args.git_ref_date(),
messages_per_batch: args.messages_per_batch(),
message_batches: args.message_batches(),
message_size: args.message_size(),
Expand Down
Loading

0 comments on commit d537a0b

Please sign in to comment.